Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamic links sometimes don't trigger the listener #1589

Closed
SimonErich opened this issue Oct 12, 2018 · 44 comments
Closed

Dynamic links sometimes don't trigger the listener #1589

SimonErich opened this issue Oct 12, 2018 · 44 comments
Labels
Service: Links Firebase Dynamic Links Type: Stale Issue has become stale - automatically added by Stale bot
Milestone

Comments

@SimonErich
Copy link

SimonErich commented Oct 12, 2018

Issue

We have integrated rnfirebase dynamic links in our app and it usually works well. But sometimes we have a quirk, where dynamic links open the app, but don't trigger the listener.

I can usually reproduce it by following these instructions:

  • i create or share a firebase dynamic link (https://xxxxx.app.goo.gl/ifdj39)
  • i open this link on an iphone 7/X and everything works fine. => app opens and the dynamic link is passed. The app navigates (via react-navigation) to a new stack screen.
  • i navigate back to the homescreen
  • i minimize the app
  • and then I click the link now

my app maximizes again correctly, but there is no dynamic link change or anything passed and so the app stays on the homescreen.

I tried to debug it, but couldn't find a way.

Here is my Podfile

    # Uncomment the next line to define a global platform for your project
    platform :ios, '9.0'

    target 'MyApp' do

      rn_path = '../node_modules/react-native'
      rn_maps_path = '../node_modules/react-native-maps'

      pod 'yoga', path: "#{rn_path}/ReactCommon/yoga/yoga.podspec"
      pod 'React', path: rn_path, subspecs: [
        'Core',
        'RCTActionSheet',
        'RCTAnimation',
        'RCTGeolocation',
        'RCTImage',
        'RCTLinkingIOS',
        'RCTNetwork',
        'RCTSettings',
        'RCTText',
        'RCTVibration',
        'RCTWebSocket'
      ]

      # Uncomment the next line if you're using Swift or would like to use dynamic frameworks
      # use_frameworks!

      # Required by RNFirebase
      pod 'Firebase/Core’, '~> 5.9.0'

      # [OPTIONAL PODS] - comment out pods for firebase products you won't be using.
      pod 'Firebase/DynamicLinks', '~> 5.9.0'
      pod 'Firebase/Performance', '~> 5.9.0'
      pod 'Firebase/Messaging', '~> 5.9.0'
      pod 'Firebase/RemoteConfig', '~> 5.9.0'

      pod 'Fabric'
      pod 'Crashlytics'

      # react native maps
      pod 'react-native-maps', path: rn_maps_path

      pod 'GoogleMaps'  # Remove this line if you don't want to support Google Maps on iOS
      pod 'react-native-google-maps', path: rn_maps_path  # Remove this line if you don't want to support Google Maps on iOS


      # linear gradient
      pod 'BVLinearGradient', :path => '../node_modules/react-native-linear-gradient'

      pod 'ReactNativePermissions', :path => '../node_modules/react-native-permissions'
      pod 'RNVectorIcons', :path => '../node_modules/react-native-vector-icons'
      pod 'RNSVG', :path => '../node_modules/react-native-svg'

      pod 'react-native-blur', :path => '../node_modules/react-native-blur'

      pod 'RNDeviceInfo', :path => '../node_modules/react-native-device-info'

    end

    post_install do |installer|
      installer.pods_project.targets.each do |target|
        if target.name == 'react-native-google-maps'
          target.build_configurations.each do |config|
            config.build_settings['CLANG_ENABLE_MODULES'] = 'No'
          end
        end
        if target.name == "React"
            target.remove_from_project
        end


          # The following is needed to ensure the "archive" step works in XCode.
          # It removes React & Yoga from the Pods project, as it is already included in the main project.
          # Without this, you'd see errors when you archive like:
          # "Multiple commands produce ... libReact.a"
          # "Multiple commands produce ... libyoga.a"

          targets_to_ignore = %w(React yoga)

          if targets_to_ignore.include? target.name
            target.remove_from_project
          end
      end
    end

Environment

  1. Application Target Platform:

iOS

  1. Development Operating System:

macOS Sierra

  1. Build Tools:

Xcode

  1. React Native version:

0.54.1 - 0.57.0 (I've tried with multiple versions in between, but same result everywhere)

  1. React Native Firebase Version:

4.3.0 - 5.0.0 (I've tried with different versions, but same result)

  1. Firebase Module:

dynamic links

  1. Are you using typescript?

no

@leonelfaugusto
Copy link

leonelfaugusto commented Oct 16, 2018

Hello, same issue here,
I notice when I click the second time on the link the app open and navigate correctly.
In a simulator on the desktop this works fine and trigger the link all the times, but in a device don't.
In Android, I don't have any issue with this.

Edit --
After some more tests, I realize that the issue only happens in the new iOS 12.
Can you confirm @SimonErich ?

@IliRusli
Copy link

I have similar issue here, but it happened if the app has already opened on the background. Dynamic links only works if the app is not open prior to receiving the link on iOS, but Android works as expected. Anyone knows how to solve it?

@poloten4uk
Copy link

Same here.
getInitialLink - works fine.
onLink - don't trigger, if the app has already opened.

@lksilva
Copy link

lksilva commented Oct 26, 2018

I have same problem here!
I realize that it happened when app is running in background on iOS and I open Deeplink twice, always in the second moment firebase.links().onLink don't trigger

@m-pol
Copy link

m-pol commented Oct 28, 2018

Same problem... no idea how to debug this. getInitialLink works every time, but onLink often doesn't get triggered correctly the first time I click a link. If it doesn't get triggered the first time, I will re-click the link and it gets triggered the second time. It only gets triggered every other time (2, 4, 6...). Happening on a real device using iOS version 12.0.

@jackcbrown89
Copy link

Any updates on this? I can't even get it to trigger on every other click. Trying on emulator and physical devices on iOS 12.0.

@jackcbrown89
Copy link

Did some exploring inside the FirebaseDynamicLinks pod and on line 63 of RNFirebaseLinks.m is:
if (dynamicLink && dynamicLink.url && error == nil) {

For some reason, dynamicLink is nil, even though I'm using the "Link preview (debug)" option from the firebase console.

getInitialLink works just fine.

@SimonErich
Copy link
Author

Yeah we still don't have a solution either and it's a really big problem for us right now.
Has anyone of you solved this problem?

@jackcbrown89
Copy link

jackcbrown89 commented Nov 6, 2018

@SimonErich I finally solved the problem today. Change this
[FIROptions defaultOptions].deepLinkURLScheme = @"https://xxxx.page.link"
to this:
[FIROptions defaultOptions].deepLinkURLScheme = @"com.example.app";
and make sure it's listed in XCode >> Info >> URL Types

Only other thing I can say is to upgrade to what they released today https://rnfirebase.io/docs/v5.x.x/release-notes#5.1.0

Thanks to this post

@SimonErich
Copy link
Author

SimonErich commented Nov 6, 2018

@jackcbrown89 thank you for coming back to share your solution.
Is that everything you did? And you are sure it's working now?

I updated react-native-firebase to 5.1.0 and also changed the url deepLinkingScheme + url types to my app identifier instead of the url, but I still have the same problem.
(in the dynamic link doc on rnfirebase it states, that you can either use your app identifier or any other unique value, so that shouldn't really make a difference as long as they are in sync. right?)

This is my AppDelegate.m file:
#import "AppDelegate.h"

#import <React/RCTBundleURLProvider.h>
#import <React/RCTRootView.h>
#import <Firebase.h>
#import "RNFirebaseLinks.h"
#import "RNSplashScreen.h"

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
  [FIROptions defaultOptions].deepLinkURLScheme = @"com.myapp.app";
  [FIRApp configure];
  
  NSURL *jsCodeLocation;
  jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil];

  RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation
                                                      moduleName:@"MyApp"
                                               initialProperties:nil
                                                   launchOptions:launchOptions];
  
  rootView.backgroundColor = [[UIColor alloc] initWithRed:1.0f green:1.0f blue:1.0f alpha:1];

  self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
  UIViewController *rootViewController = [UIViewController new];
  rootViewController.view = rootView;
  
  self.window.rootViewController = rootViewController;
  [self.window makeKeyAndVisible];

  [RNSplashScreen show];

  return YES;
}

- (BOOL)application:(UIApplication *)application
            openURL:(NSURL *)url
            options:(NSDictionary<NSString *, id> *)options {
  return [[RNFirebaseLinks instance] application:application openURL:url options:options];
}

- (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity
 restorationHandler:(void (^)(NSArray * _Nullable))restorationHandler
{
  return [[RNFirebaseLinks instance] application:application continueUserActivity:userActivity restorationHandler:restorationHandler];
}

@end

Under XCode -> Capabilities -> Associated domains I have:
applinks:nzh323.app.goo.gl (we are still using the older URL scheme - could that be a problem ? although, I've also tried with a new one and same error)

And I've added a URL type with Identifier BundleID and the url scheme com.myapp.app

@jackcbrown89
Copy link

@SimonErich Could you share your info.plist, entitlements file, and link details (from firebase console)? Also, the old scheme should be fine.

@leonelfaugusto
Copy link

@jackcbrown89 thanks for sharing your solutions, for me doesn't work too.
Update to 5.1 and change [FIROptions defaultOptions].deepLinkURLScheme and the problem persist.

Thanks.

@SimonErich
Copy link
Author

I just checked everything again and in my AppDelegate.m file I get the following warning from XCode:

Conflicting parameter types in implementation of 
'application:continueUserActivity:restorationHandler:': 'void (^ _Nonnull __strong) 
(NSArray<id<UIUserActivityRestoring>> * _Nullable __strong)' vs 'void (^__strong _Nonnull)(NSArray 
 * _Nullable __strong)'

Maybe this has something to do with the problem?
I've searched for this warning and found the issue #1592, which is tagged to be resolved in react-native-firebase 6.0.0.
Could that be part of the problem?

Here are the files:
info.plist: https://pastebin.com/bXBNaQNz
entitlements file: https://pastebin.com/tT6J1LNY

@SimonErich
Copy link
Author

Hmmm this is weird.
I have tried to implement deep linking with react natives Linking module as described here:
https://facebook.github.io/react-native/docs/linking

But it seems like it has the same behavior.
Most of the time I get the link, but sometimes not.

I have only tried it using the firebase short links (xxx.app.goo.g/yyyy) and most of the time it worked, but sometimes the listener of Linking was not called.
For that reason I don't know whether it is a react-native, firebase or rnfirebase problem.

Can any of you confirm this behavior with react-natives Linking.
Or can any of you narrow it down a bit to find out where to dump the issue. (react-native project or here)

@kaladivo
Copy link

kaladivo commented Nov 9, 2018

I think I have found the issue.

I was debugging the native RNfirebase code. Although I don't know objective C I have found that every second time the app is brought to foreground by link it fails right here with the following error: -[RNFirebaseLinks application:continueUserActivity:restorationHandler:]_block_invoke [Line 80] Failed to handle universal link: LINK error Error Domain=NSPOSIXErrorDomain Code=53 "Software caused connection abort" UserInfo={_kCFStreamErrorCodeKey=53, _kCFStreamErrorDomainKey=1} (where the LINK is the actual link)

I have no idea how to solve this issue but maybe this info could help someone who knows how to solve it....

@SimonErich
Copy link
Author

Anyone managed to solve this yet?
How did you deal with it? Are there any alternatives maybe?

@jackcbrown89
Copy link

@SimonErich could you share a gif of this happening with the same dynamic link?

@Salakar
Copy link
Member

Salakar commented Nov 17, 2018

I think @kaladivo has stumbled onto one of the causes, if you're on iOS 12 then it's most likely that that is the issue, it's a bug in iOS it seems and it's not just this lib that has the issue; see https://github.com/AFNetworking/AFNetworking/issues/4279

There are some suggestions on there on how to work around it / temporarily patch it (e.g. https://github.com/AFNetworking/AFNetworking/issues/4279#issuecomment-427830725). If anyone can get it working with one of those and send a PR over that'd be great 👌

@Salakar Salakar added Service: Links Firebase Dynamic Links ios12 Workflow: Waiting for User Response Blocked waiting for user response. Workflow: Needs Review Pending feedback or review from a maintainer. labels Nov 17, 2018
@IcebergRage
Copy link

Hello !
I have this bug too.
In the XCode console, i got this :

[RNFirebaseLinks application:continueUserActivity:restorationHandler:]_block_invoke [Line 67] Failed to handle universal link: my.page.link.url

my conf :
RN 0.57.8
react-native-firebase : 5.1.0-rc2
test on iphone 6s device.

How do you deal with it ?

@Vanclief
Copy link

Vanclief commented Jan 9, 2019

Having exactly the same problem but only for iOS.

getInitialLink(): Works fine on Android and iOS
onLink(): Is not triggered for iOS if the application is already opened

@linnett
Copy link

linnett commented Jan 17, 2019

Also same issue on iOS.

Although getInitialLink() not working when installing the app from a specific link!

@Salakar
Copy link
Member

Salakar commented Jan 18, 2019

Have landed @benschell PR which should solve this issue. It'll be in the next release. Let me know if I can go ahead and close this.

@Salakar Salakar added Resolution: Fixed A fix has been merged into master. and removed Workflow: Needs Review Pending feedback or review from a maintainer. labels Jan 18, 2019
@poloten4uk
Copy link

@Salakar Thanks, man :)

@Salakar
Copy link
Member

Salakar commented Jan 22, 2019

v5.2.1 is up. Thanks all 👍


Loving react-native-firebase and the support we provide? Please consider supporting us with any of the below:

@OzzieOrca
Copy link

We still seem to be experiencing this issue on 5.2.1. I've upgraded pods too. I'm confused why the workaround didn't work for us. I don't have a very good way to share how to reproduce it as it's in a large app. Just wanted to see if anyone else is still having this issue.

@cbrwizard
Copy link

cbrwizard commented Feb 22, 2019

Hey, 5.2.1 didn't help me on iOS 12. It works on initial url open, but not when app is already in the background.

Update: nope, seems to be fixed. My problem was that I subscribed to url event with RN's native Linking function. I had to subscribe with firebase.links().onLink instead

@romit07
Copy link

romit07 commented Mar 27, 2019

@OzzieOrca have you solved it? I'm still getting the same issue

@FrankGoortani
Copy link

I still have the same issue. When opening the link from browser, This works fine but when this link is inside another app I get the following error
-[RNFirebaseLinks application:continueUserActivity:restorationHandler:]_block_invoke [Line 83] Failed to handle universal link: asdf.page.link Any solution for this?

@lironsher
Copy link

@FrankGoortani did you solved it?
Have the same issue

@mehuleo
Copy link

mehuleo commented Aug 10, 2019

I have found a workaround:
Open Libraries/RNFirebase.xcodeproject/RNFirebase/links/RNFirebaseLinks.m in xCode
Make sure your code is upto date with this commit: 29d0061

Now, edit the next line after [self sendJSEvent:self name:LINKS_LINK_RECEIVED body:url.absoluteString]; — mostly line# 66 or 71 — to look like following:

} else if (error != nil && (([NSPOSIXErrorDomain isEqualToString:error.domain] && error.code == 53) || [NSURLErrorDomain isEqualToString:error.domain])) {                    

The issue as per me is that most of the time in iOS while waking up from background firebase tries to resolve the URL too quick and iOS throws Returning ENOTCONN because protocol has not yet been set up.

@mikehardy
Copy link
Collaborator

@Salakar check out that tidbit from @mehuleo - looks very interesting - does the reasoning appear sound to you? Maybe @mehuleo could propose a PR? @mehuleo - just to make sure - you saw errors before, and then after adding the extra boolean test for NSURLErrorDomain to trigger retry in that case, you see more success?

@mikehardy mikehardy reopened this Aug 10, 2019
@mikehardy mikehardy added the Workflow: Waiting for User Response Blocked waiting for user response. label Aug 10, 2019
@stale
Copy link

stale bot commented Sep 7, 2019

Hello 👋, to help manage issues we automatically close stale issues.
This issue has been automatically marked as stale because it has not had activity for quite some time. Has this issue been fixed, or does it still require the community's attention?

This issue will be closed in 15 days if no further activity occurs.
Thank you for your contributions.

@stale stale bot added the Type: Stale Issue has become stale - automatically added by Stale bot label Sep 7, 2019
@stale
Copy link

stale bot commented Sep 22, 2019

Closing this issue after a prolonged period of inactivity. If this is still present in the latest release, please feel free to create a new issue with up-to-date information.

@stale stale bot closed this as completed Sep 22, 2019
@minuhariharan
Copy link

I have the same problem.When the app is running in background on iOS and I open the link twice or open 2 links one after the other, always the second moment firebase.links().onLink does not trigger. If I open a link and then open the second link after say 2-3 minutes, then it opens.

@getumangon
Copy link

Same problem happening with me too. getInitialLink works every time, but onLink often doesn't get triggered correctly. It triggered the first time. In the second time it is not triggering. It only gets triggered every other time (1, 3, 5...). Happening on a real device using iOS version 13.3.1.

"react-native-firebase": "^5.6.0",

@IcebergRage
Copy link

Can you try with 5.5.6 and tell me if you have the same problem ?

@getumangon
Copy link

@IcebergRage Downgrading the version did the trick! Thanks a ton.

@mikehardy
Copy link
Collaborator

Hey @IcebergRage / @getumangon that's very interesting but not the intended effect. Can someone post a PR that fixes that regression and I can get another 5.x build out.

There are not many commits between v5.5.6 tag and tip of v5.x.x branch v5.5.6...v5.x.x - it has to be in there somewhere and I'd welcome a PR

@mikehardy
Copy link
Collaborator

Honestly - going through that diff - all I see SDK update from 6.8.0 to 6.13.0. I wonder if you could use v5.6.0 with SDK 6.8.0 and it would work? Or if you updated all the way to 6.24.0 if it would work - in other words if this is/was just an upstream SDK issue in those versions. Note that the point of the v5.x.x maintenance is to allow use of modern SDKs so you should be able to compile and use iOS SDK 6.24.0 without problems (I do in my project)

@guisalvadori
Copy link

I have the same issue on Android. I'm using dynamic links 6.7.1, getInitialLink() works very well, but onLink works only with a second time click.
Any suggestion?

@jkim430
Copy link

jkim430 commented Aug 19, 2020

Why is this issue closed? Seems like the problem isn't fixed.

I'm also experiencing this issue - here's my config:

"@react-native-firebase/app": "^8.2.0",
"@react-native-firebase/dynamic-links": "^7.4.2",
"react-native": "0.61.5",

When I launch the app from closed state, getInitialLink gets consistently triggered. However when I launch from the background state, onLink is inconsistently triggered. There doesn't seem to be a consistent pattern either, like every other time. I've only been able to successfully trigger onLink up to 3 times in a row, so the issue is quite frequent.

Whenever onLink fails to trigger, Xcode log shows the following error:

RNFBDynamicLinks: Unknown error occurred when attempting to handle a universal link: Error Domain=NSURLErrorDomain Code=-1005 "The network connection was lost."

@mikehardy
Copy link
Collaborator

@jkim430 because it was opened almost 2 years ago? Open a new issue with full details. The amount of change in upstream SDKs and this module in 2 years is difficult to imagine

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Service: Links Firebase Dynamic Links Type: Stale Issue has become stale - automatically added by Stale bot
Projects
None yet
Development

No branches or pull requests