Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React native deep linking vs Facebook SDK conflct

I'm using the Facebook SDK in my react-native app, and now I want to add support for universal deep linking as well.

I modified my appdelegate per the instructions here: https://developers.facebook.com/docs/ios/getting-started/

For deep linking, I'm trying to follow this: https://facebook.github.io/react-native/docs/linking.html

However, they both seem to use the same method, and I'm not sure how to reconcile:

````

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url
  sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
  return [RCTLinkingManager application:application openURL:url
                      sourceApplication:sourceApplication annotation:annotation];
}
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
    return [[FBSDKApplicationDelegate sharedInstance] application:application
                                                          openURL:url
                                                sourceApplication:sourceApplication
                                                       annotation:annotation];
}

````

Please let me know how I should modify the method to have both capabilities.

Thank you

like image 942
erdostom Avatar asked Sep 01 '16 20:09

erdostom


3 Answers

This is how I managed to solve the issue:

- (BOOL)application:(UIApplication *)application
            openURL:(NSURL *)url
            options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {

  NSString *myUrl = url.absoluteString;
  if ([myUrl containsString:@"PLACE_YOUR_FB_APP_ID_HERE"]) {
    return [[FBSDKApplicationDelegate sharedInstance] application:application
                                                                openURL:url
                                                      sourceApplication:options[UIApplicationOpenURLOptionsSourceApplicationKey]
                                                             annotation:options[UIApplicationOpenURLOptionsAnnotationKey]
                  ];
  } else {
    return [RCTLinkingManager application:application openURL:url options:options];
  }
}

Just replace the PLACE_YOUR_FB_APP_ID_HERE with the string from your info.plist. For example, in the following case its fb9999999999:

  <array>
    <dict>
      <key>CFBundleURLSchemes</key>
      <array>
        <string>fb9999999999</string>
      </array>
    </dict>
  </array>
like image 149
Asaf David Avatar answered Oct 25 '22 21:10

Asaf David


Ended up writing a simple if statement to see if the incoming URL was a Facebook one, and returning the FBSDKApplicationDelegate if it was, and the RCTLinkingManager object if it wasn't.

like image 1
erdostom Avatar answered Oct 25 '22 21:10

erdostom


Building off of what @erdostom wrote earlier (this was a lifesaver insight btw, thanks!) here's how I updated my AppDelegate.m

In the method supplied by the fbsdk, instead of returning 'handled',

- (BOOL)application:(UIApplication *)application
            openURL:(NSURL *)url
            options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {

  NSString *myUrl = url.absoluteString;
  if ([myUrl containsString:@"nameONonFBUrl"]) {
    return [RCTLinkingManager application:application
                                          openURL:url
                                sourceApplication:options[UIApplicationOpenURLOptionsSourceApplicationKey]
                                       annotation:options[UIApplicationOpenURLOptionsAnnotationKey]];
  } else {
    return [[FBSDKApplicationDelegate sharedInstance] application:application
                                                                  openURL:url
                                                        sourceApplication:options[UIApplicationOpenURLOptionsSourceApplicationKey]
                                                               annotation:options[UIApplicationOpenURLOptionsAnnotationKey]];
  }
}
like image 1
dcordz Avatar answered Oct 25 '22 22:10

dcordz