react-native-firebase icon indicating copy to clipboard operation
react-native-firebase copied to clipboard

Dynamic links sometimes don't trigger the listener

Open SimonErich opened this issue 8 years ago • 44 comments

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

SimonErich avatar Oct 12 '18 16:10 SimonErich

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 ?

leonelfaugusto avatar Oct 16 '18 12:10 leonelfaugusto

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?

IliRusli avatar Oct 22 '18 08:10 IliRusli

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

poloten4uk avatar Oct 25 '18 12:10 poloten4uk

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

lksilva avatar Oct 26 '18 17:10 lksilva

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.

m-pol avatar Oct 28 '18 18:10 m-pol

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 avatar Oct 30 '18 16:10 jackcbrown89

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.

jackcbrown89 avatar Oct 30 '18 20:10 jackcbrown89

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?

SimonErich avatar Nov 05 '18 23:11 SimonErich

@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

jackcbrown89 avatar Nov 06 '18 01:11 jackcbrown89

@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

SimonErich avatar Nov 06 '18 08:11 SimonErich

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

jackcbrown89 avatar Nov 06 '18 15:11 jackcbrown89

@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.

leonelfaugusto avatar Nov 06 '18 16:11 leonelfaugusto

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 avatar Nov 07 '18 10:11 SimonErich

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)

SimonErich avatar Nov 07 '18 14:11 SimonErich

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....

kaladivo avatar Nov 09 '18 09:11 kaladivo

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

SimonErich avatar Nov 16 '18 16:11 SimonErich

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

jackcbrown89 avatar Nov 16 '18 17:11 jackcbrown89

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 avatar Nov 17 '18 01:11 Salakar

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 ?

IcebergRage avatar Jan 08 '19 14:01 IcebergRage

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

Vanclief avatar Jan 09 '19 19:01 Vanclief