响应本机深层链接与Facebook SDK冲突 [英] React native deep linking vs Facebook SDK conflct
问题描述
我在我的react-native应用程序中使用Facebook SDK,现在我也想添加对通用深层链接的支持.
I'm using the Facebook SDK in my react-native app, and now I want to add support for universal deep linking as well.
我按照此处的说明修改了我的appdelegate: https://developers.facebook. com/docs/ios/getting-started/
I modified my appdelegate per the instructions here: https://developers.facebook.com/docs/ios/getting-started/
对于深层链接,我尝试遵循此规则: https://facebook.github.io/react-native/docs/linking.html
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.
谢谢
推荐答案
这是我设法解决此问题的方法:
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];
}
}
只需用info.plist中的字符串替换PLACE_YOUR_FB_APP_ID_HERE
.例如,在以下情况下,其为fb9999999999:
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>
这篇关于响应本机深层链接与Facebook SDK冲突的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!