新的Facebook SDK FBSession sessionOpenWithPermissions [英] New Facebook SDK FBSession sessionOpenWithPermissions
问题描述
我一直在尝试使用Facebook开发iOS应用程序而且我是新手。所以我一直试图用Facebook登录
I've been trying to develop iOS app using Facebook and I'm new. So I've been trying to make
登录Facebook,然后尝试实施它。
a login with Facebook, followed a tutorial on Facebook and try to implement it.
但我遇到过, [FBSession sessionOpenWithPermissions]
未找到。当我运行
But I've encountered, [FBSession sessionOpenWithPermissions]
not found. When I run the
应用时,它会强制关闭并说出错误。构建项目时,它将显示警告
app, it will force close and say that error. When build the project, it will show warning
在 sessionOpenWithPermission
的黄色感叹号> FBSession
yellow exclamation that sessionOpenWithPermission
is not found in FBSession
该教程已过时?如果是,那么新的Facebook SDK的新代码是什么
The tutorial outdated? If it is, then what is the new code for the new Facebook SDK for
sessionOpenWithPermission?
sessionOpenWithPermission ?
推荐答案
也许这段代码可以帮助你,把它放在你的 AppDelegate.m
类
Maybe this code helps you, put it in your AppDelegate.m
class
- (void)sessionStateChanged:(FBSession *)session
state:(FBSessionState) state
error:(NSError *)error
{
switch (state) {
case FBSessionStateOpen: {
self.loggedinVCController = [[LoggedinVC alloc] initWithNibName:@"LoggedinVC" bundle:nil];
self.navController = [[UINavigationController alloc]initWithRootViewController:self.loggedinVCController];
self.window.rootViewControlle`enter code here`r = self.navController;
}
break;
case FBSessionStateClosed:
case FBSessionStateClosedLoginFailed:
// Once the user has logged in, we want them to
// be looking at the root view.
[self.navController popToRootViewControllerAnimated:NO];
[FBSession.activeSession closeAndClearTokenInformation];
self.viewController = [[SampleViewController alloc] initWithNibName:@"SampleViewController" bundle:nil];
self.window.rootViewController = self.viewController;
break;
default:
break;
}
if (error) {
UIAlertView *alertView = [[UIAlertView alloc]
initWithTitle:@"Error"
message:error.localizedDescription
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alertView show];
}
}
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation
{
return [FBSession.activeSession handleOpenURL:url];
}
- (void)openSession
{
[FBSession openActiveSessionWithReadPermissions:nil
allowLoginUI:YES
completionHandler:
^(FBSession *session,
FBSessionState state, NSError *error) {
[self sessionStateChanged:session state:state error:error];
}];
}
这篇关于新的Facebook SDK FBSession sessionOpenWithPermissions的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!