确定Dropbox或Facebook SDK是否应该处理应用程序委托调用

时间:2015-08-29 19:32:25

标签: ios objective-c facebook facebook-graph-api

我必须将最新的FB-SDK集成到我的iOS应用程序中 - 噩梦从应用代表开始。

文档说要在app delegate中实现它:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  return [[FBSDKApplicationDelegate sharedInstance] application:application
    didFinishLaunchingWithOptions:launchOptions];
}

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

但我的应用不仅适用于FB,也适用于Dropbox和YouTube上传。

所以我的application:openURL:方法现在看起来像这样:

- (BOOL)application:(UIApplication *)application
            openURL:(NSURL *)url
  sourceApplication:(NSString *)sourceApplication
         annotation:(id)annotation {

    [[UIApplication sharedApplication] setIdleTimerDisabled:YES];

    // Facebook

    if([FBSession.activeSession handleOpenURL:url]){
        BOOL result = [FBSession.activeSession handleOpenURL:url];
        return result;
    }

    // Dropbox

    if ([[DBSession sharedSession] handleOpenURL:url]) {
        if ([[DBSession sharedSession] isLinked]) {
            NSLog(@"App linked successfully!");

        }
        return YES;
    }
    // Add whatever other url handling code your app requires here
    return NO;
}
但是,{p> FBSession并不存在。那么如何区分Facebook和Dropbox的openURL:来电?

0 个答案:

没有答案