将Facebook SDK更新至3.5后无法打开活动会话

在将Facebook sdk更新为3.5之后,当尝试执行openActiveSessionWithReadPermissions时,操作失败。 这里是打开会话和处理callback的片段:

[FBSession openActiveSessionWithReadPermissions:@[@"email", @"user_hometown", @"user_location", @"user_birthday"] allowLoginUI:YES completionHandler: ^(FBSession *session, FBSessionState state, NSError *error) { switch (state) { case FBSessionStateCreatedTokenLoaded: case FBSessionStateOpenTokenExtended: case FBSessionStateOpen: { completion(TRUE); break; } case FBSessionStateClosed: case FBSessionStateClosedLoginFailed: completion(FALSE); [FBSession.activeSession closeAndClearTokenInformation]; break; default: break; } }]; 

我最终在FBSessionStateClosedLoginFailed的情况下,我得到一个FBSKLog如下:

 FBSDKLog: Cannot use the Facebook app or Safari to authorize, fb123456789012345 is not registered as a URL Scheme 

我有同样的问题(Facebook SDK 3.5.1)

我的Facebook的URLscheme是Info.plist URLscheme中的第1项。 通过将其移动到项目0来解决问题。

我有同样的问题。 上面的代码解决了这个问题。 你必须用文本编辑器编辑你的.plist文件。 但在Xcode中,你不会看到任何改变。 而不是URLtypes – CFBundleURLTypes而不是URL Schemes应该是CFBundleURLSchemes。

 <key>CFBundleURLTypes</key> <array> <dict> <key>CFBundleURLSchemes</key> <array> <string>fb48524**********</string> </array> </dict> </array> 

似乎我有一个URL计划,不符合我的FacebookAppId。 无论出于何种原因,这似乎不是以前的问题,但现在是相关的。 确保你的Facebook URL Scheme是你的FacebookAppID前缀fb(在.plist文件中)。 例如:

FacebookAppId: 123456789012345

urltypes – >项目0 – > URL Schemes – >项目0: fb123456789012345

 adding URL Scheme in plist file is solved my problem <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <array> <dict> <key>CFBundleURLSchemes</key> <array> <string>fb8947128947(fb<App ID>)</string> </array> </dict> </array> </plist> 

我得到相同的错误,但通过下面的info.plist层次结构解决:

 ` <key>URL Types</key> <array> <dict> <key>URL Schemes</key> <array> <string>fb***</string> </array> </dict> </array> ` 

萝拉的答案为我工作。 如果您有多个URLtypes(例如Facebook和一个用于您的应用),那么给您自己处理一个等于您应用的捆绑包标识符的捆绑标识符,然后遍历您的URLtypes以find它是有帮助的。

在我的应用程序委托的开始,我只是运行:

 NSArray *urlSchemes = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleURLTypes"]; for (NSDictionary *scheme in urlSchemes) { if ([[scheme objectForKey:@"CFBundleURLName"] isEqualToString:[[NSBundle mainBundle] bundleIdentifier]]) { self.urlScheme = [[scheme objectForKey:@"CFBundleURLSchemes"] objectAtIndex:0]; break; } } 

然后(因为我们有不同的FB应用程序ID的多个环境)

 -(BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation { if ([url.scheme hasPrefix:@"fb"]) { //Facebook callback return [FBSession.activeSession handleOpenURL:url]; // else handle your own URL here