我已按照说明从我的应用程序实现登录到 Facebook 的过程:
https://developers.facebook.com/docs/mobile/ios/build/#implementsso
这是我的代码:
- (IBAction)facebookButton:(id)sender {
facebook = [[Facebook alloc] initWithAppId:@"383032031757454" andDelegate:self];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
if ([defaults objectForKey:@"FBAccessTokenKey"]
&& [defaults objectForKey:@"FBExpirationDateKey"]) {
facebook.accessToken = [defaults objectForKey:@"FBAccessTokenKey"];
facebook.expirationDate = [defaults objectForKey:@"FBExpirationDateKey"];
}
if (![facebook isSessionValid]) {
NSArray *permissions = [[NSArray alloc] initWithObjects:
@"user_likes",
@"read_stream",
nil];
[facebook authorize:permissions];
permissions=nil;
}
}
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
return [facebook handleOpenURL:url];
}
- (void)fbDidLogin {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:[facebook accessToken] forKey:@"FBAccessTokenKey"];
[defaults setObject:[facebook expirationDate] forKey:@"FBExpirationDateKey"];
[defaults synchronize];
}
登录并允许应用程序权限后,Safari 仍处于打开状态,我必须手动返回我的应用程序,但 SDK 提供的示例应用程序“Hackbook”在接受权限并在 Safari 中登录后,它会关闭 Safari 并返回到应用程序。我也想做同样的事,但我没有成功。
这是 .plist 文件:
谢谢