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
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>
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.
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]];
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With