在我的应用程序中,可以选择使用Facebook登录.
在iOS 9.3上可以正常工作.
- (void)FacbookLoginButtonpressed:(id)sender { [self showLoader]; FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init]; [login logInWithReadPermissions: @[@"public_profile",@"email"] fromViewController:self handler:^(FBSDKLoginManagerLoginResult *result,NSError *error) { if (error) { NSLog(@"Process error"); [self hideLoader]; [self showError:@"Error" message:@"Please try to use other login option"]; } else if (result.isCancelled) { NSLog(@"Cancelled"); [self hideLoader]; [self showError:@"Error" message:@"Please try to use other login option"]; } else { [self loginButton:sender didCompleteWithResult:result error:error]; NSLog(@"Logged in"); } }]; }
self是我的ViewController调用loginViewController显示的按钮,它继承自UIViewController
我的应用程序使用此图书馆幻灯片导航:https://github.com/aryaxt/iOS-Slide-Menu
显示loginViewController屏幕有两个选项:
1.
从常规屏幕(继承自UIViewController),有一个按钮,点击此代码运行:
UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Main" bundle:nil]; UIViewController *vc = [sb instantiateViewControllerWithIdentifier:@"loginScreen"; [self presentViewController:vc animated:YES completion:nil];
这项工作很好,我可以成功登录Facebook.
2.
从其他屏幕也继承自UIViewController,但这个屏幕是幻灯片菜单,我有这个代码在AppDelegate
UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Main" bundle:nil]; MenuViewController *menu = [sb instantiateViewControllerWithIdentifier:@"MenuViewController"; [SlideNavigationController sharedInstance].rightMenu = menu;
使用此选项,Facebook登录不起作用(空白屏幕)
为了尝试使之成为行动:
>更新到最新的facebook SDK – 使用这个:https://developers.facebook.com/docs/ios/getting-started
>启用钥匙串共享 – 使用此功能:https://stackoverflow.com/a/38799196/867694
当loginViewController从菜单(第二个选项)出现时,我在日志中唯一的事情是这样的:
Presenting view controllers on detached view controllers is discouraged <loginViewController: 0x7622fb0>.
我能做什么?
解决方法
我终于修复了,在MenuViewController中我改变了将loginViewController呈现给这个的方式:
[self.view.window.rootViewController presentViewController:vc animated:YES completion:nil];