我必须将最新的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:
来电?