2016-09-01 81 views
2

我在我的react-native應用程序中使用Facebook SDK,現在我想添加對通用深度鏈接的支持。反應原生深度鏈接vs Facebook SDK conflct

我修改每這裏說明我的appdelegate:https://developers.facebook.com/docs/ios/getting-started/

深層鏈接,我想按照這個:https://facebook.github.io/react-native/docs/linking.html

然而,他們似乎都使用同樣的方法,我不知道如何調和:

````

- (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]; 
} 

````

請讓我知道我應該如何修改該方法以具備這兩種功能。

謝謝

回答

0

最後寫一個簡單的if語句來看看如果傳入URL是Facebook的一個,並返回FBSDKApplicationDelegate如果是,和RCTLinkingManager對象,如果事實並非如此。

0

大廈掉什麼@erdostom之前寫的(這是一個救星洞察力順便說一句,謝謝!)這裏就是我如何更新我的AppDelegate.m

在由fbsdk提供的方法,而不是返回「處理」,

- (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]]; 
    } 
} 
0

這是我如何設法解決這一問題:

- (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:

<array> 
    <dict> 
     <key>CFBundleURLSchemes</key> 
     <array> 
     <string>fb9999999999</string> 
     </array> 
    </dict> 
    </array>