2016-09-18 68 views
10

在我的应用程序中有一个选项用Facebook登录。目标c - iOS 10 Facebook登录空白屏幕

在iOS 9.3上,它工作正常。

当我在iOS 10.0.1上测试它时,它显示出一个空白屏幕。 enter image description here

我使用此代码来启动登录过程:

- (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登录不起作用(黑屏),我为了尽量使工作做

操作:

  1. 更新到最新的Facebook SDK - 全光照克这种:https://developers.facebook.com/docs/ios/getting-started
  2. 启用钥匙扣共享 - 使用此:https://stackoverflow.com/a/38799196/867694

,我有在日志中,当loginViewController从菜单(第二个选项)出现的唯一的事情是这样的:

Presenting view controllers on detached view controllers is discouraged <loginViewController: 0x7622fb0>. 

我能做什么?

+0

问题在于呈现SafariViewController的方式。在iOS 10中,Apple添加了一些代码来禁止使用隐藏的SafariVC(我在这里写了这篇文章[http://stackoverflow.com/questions/39019352/ios10-sfsafariviewcontroller-not-working-when-alpha-is-set- 0)),它似乎它打破了你的行为。检查此[回答](http://stackoverflow.com/a/39386491/1044073)类似的问题,它可能会建议你一个解决方案。 –

回答

8

我终于修好了,在MenuViewController我改变呈现loginViewController此方式:

[self.view.window.rootViewController presentViewController:vc animated:YES completion:nil]; 
0
[self presentViewController:vc animated:YES completion:nil] 

更换

[self.view.window.rootViewController presentViewController:vc animated:YES completion:nil] 

,并尝试

9

在iOS系统10你需要openURL的另一个实现:

#ifdef __IPHONE_9_0 
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url options:(NSDictionary *)options { 

    [[FBSDKApplicationDelegate sharedInstance] application:application openURL:url sourceApplication:options[UIApplicationOpenURLOptionsSourceApplicationKey] annotation:options[UIApplicationOpenURLOptionsAnnotationKey]]; 

    return YES; 
} 
#else 
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation { 
    [[FBSDKApplicationDelegate sharedInstance] application:application openURL:url sourceApplication:sourceApplication annotation:annotation]; 

    return YES; 
} 
#endif 
+0

谢谢,这是iOS10的答案! –

+1

根据官方Apple文档,后一种方法在iOS 9.0中已弃用。这怎么能成为_later_ OS的答案? – BaseZen

0

请确保你写下面的代码:

[window makeKeyAndVisible]; 

didFinishLaunchingWithOptions 
0
func loginAction() { 

    let manager = LoginManager.init(loginBehavior: LoginBehavior.web, defaultAudience: LoginDefaultAudience.friends) 
    manager.logIn([.publicProfile, .email, .userFriends], viewController: self.navigationController, completion: { (loginResult) in 

     print("LOGIN RESULT! \(loginResult)") 
     switch loginResult { 
     case .failed(let error): 
      print("FACEBOOK LOGIN FAILED: \(error)") 
     case .cancelled: 
      print("User cancelled login.") 
     case .success(let grantedPermissions, let declinedPermissions, let accessToken): 
      print("Logged in!") 
      print("GRANTED PERMISSIONS: \(grantedPermissions)") 
      print("DECLINED PERMISSIONS: \(declinedPermissions)") 
      print("ACCESS TOKEN \(accessToken)") 
     } 
    }) 
} 

我改变的viewController从selfself.navigationController和它的作品。