2016-09-18 36 views
10

Trong ứng dụng của tôi có một tùy chọn để đăng nhập bằng Facebook.Mục tiêu c - iOS 10 Đăng nhập Facebook màn hình trống

Trên iOS 9.3, nó hoạt động OK.

Khi tôi thử nghiệm trên iOS 10.0.1, nó hiển thị cho tôi một màn hình trống. enter image description here

Tôi đang sử dụng mã này để bắt đầu quá trình đăng nhập:

- (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 là ViewController tôi gọi loginViewController hiển thị nút, nó kế thừa từ UIViewController

Ứng dụng của tôi sử dụng thư viện này cho điều hướng trang trình bày: https://github.com/aryaxt/iOS-Slide-Menu

Có hai tùy chọn để hiển thị màn hình loginViewController:

1. Từ màn hình thường xuyên (kế thừa từ UIViewController), có một nút, mà trên nhấp chuột mã này chạy:

UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Main" bundle:nil]; 
UIViewController *vc = [sb instantiateViewControllerWithIdentifier:@"loginScreen"; 
[self presentViewController:vc animated:YES completion:nil]; 

của làm việc tốt đó, tôi có thể đăng nhập với Facebook thành công.

2. Từ màn hình khác cũng kế thừa từ UIViewController, nhưng màn hình này là menu trượt, và tôi có mã này trong AppDelegate

UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Main" bundle:nil]; 
MenuViewController *menu = [sb instantiateViewControllerWithIdentifier:@"MenuViewController"; 
[SlideNavigationController sharedInstance].rightMenu = menu; 

Sử dụng tùy chọn này, facebook đăng nhập không hoạt động (màn hình trống)

hành động mà tôi đã làm để cố gắng làm cho nó hoạt động:

  1. cập nhật vào facebook SDK mới nhất - usin g này: https://developers.facebook.com/docs/ios/getting-started
  2. Bật chia sẻ keychain - sử dụng này: https://stackoverflow.com/a/38799196/867694

Điều duy nhất mà tôi có trong nhật ký khi loginViewController xuất hiện từ thực đơn (tùy chọn thứ 2) là thế này:

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

Tôi có thể làm gì?

+0

Vấn đề là trong cách trình bày SafariViewController. Trong iOS 10 Apple đã thêm một số mã để cấm sử dụng SafariVC ẩn (tôi đã viết về điều này [ở đây] (http://stackoverflow.com/questions/39019352/ios10-sfsafariviewcontroller-not-working-when-alpha-is-set- to-0)) và có vẻ như nó kích thích hành vi của bạn. Kiểm tra [answer] (http://stackoverflow.com/a/39386491/1044073) cho câu hỏi tương tự, nó có thể gợi ý cho bạn một giải pháp. –

Trả lời

8

Cuối cùng tôi cố định nó, trong MenuViewController Tôi đổi cách trình bày loginViewController này:

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

thay thế với

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

và thử

9

Ở iOS 10 bạn cần triển khai khác cho 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

Cảm ơn bạn, đây là câu trả lời cho iOS10! –

+1

Phương pháp thứ hai không được chấp nhận tại iOS 9.0 theo tài liệu chính thức của Apple. Làm thế nào điều này có thể là câu trả lời cho một hệ điều hành _later_? – BaseZen

0

Hãy chắc chắn rằng, bạn viết đoạn mã sau:

[window makeKeyAndVisible]; 

trong

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)") 
     } 
    }) 
} 

tôi đã thay đổi viewController self-self.navigationController và nó hoạt động.

Các vấn đề liên quan