11

In my app there is an option to login with Facebook.

On iOS 9.3 it's works OK.

When I testing it on iOS 10.0.1, it's shows me a blank screen. enter image description here

I'm using this code to start the login process:

- (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 is my ViewController calls loginViewController that shows the button, it inherit from UIViewController

My app using this library for slide navigation: https://github.com/aryaxt/iOS-Slide-Menu

There is two options to show the loginViewController screen:

1. From regular screen (inherit from UIViewController), there is a button, that on click this codes run:

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

That work's fine, I'm able to login with Facebook successfully.

2. From other screen that also inherit from UIViewController, but this screen is the slide menu, and I have this code in the AppDelegate

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

Using this option, the facebook login doesn't work (blank screen)

Action that I did in order to try make it works:

  1. Update to the latest facebook SDK - using this: https://developers.facebook.com/docs/ios/getting-started
  2. Enable keychain sharing - using this: https://stackoverflow.com/a/38799196/867694

The only thing that I have in the log when the loginViewController appears from the menu (2nd option) is this:

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

What can I do?

Community
  • 1
  • 1
Nir
  • 1,882
  • 4
  • 26
  • 44
  • The problem is in the way of presenting SafariViewController. In iOS 10 Apple added some code to prohibit usage of hidden SafariVC (I wrote about this [here](http://stackoverflow.com/questions/39019352/ios10-sfsafariviewcontroller-not-working-when-alpha-is-set-to-0)) and it seems that it brokes your behavior. Check this [answer](http://stackoverflow.com/a/39386491/1044073) for similar question, it may suggest you a solution. – Roman Ermolov Sep 18 '16 at 09:23

7 Answers7

10

I finally fixed it, in MenuViewController I changed the way to present the loginViewController to this:

[self.view.window.rootViewController presentViewController:vc animated:YES completion:nil];
Nir
  • 1,882
  • 4
  • 26
  • 44
10

In iOS 10 you need another implementation for 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
Kirill
  • 111
  • 3
0
[self presentViewController:vc animated:YES completion:nil] 

replace with

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

and try

RakeshDipuna
  • 1,570
  • 13
  • 19
0

Please make sure, you write the following code:

[window makeKeyAndVisible];

in

didFinishLaunchingWithOptions
pankaj asudani
  • 862
  • 6
  • 18
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)")
        }
    })
}

I changed viewController from self to self.navigationController and it works.

Winter
  • 3,894
  • 7
  • 24
  • 56
0

After trying all the solutions found on the web, this is what worked for me.

PFFacebookUtils.facebookLoginManager().loginBehavior = FBSDKLoginBehavior.web

(The problem is in iOS10, it tried to use loginBehavior of "browser" which leads to the blank page), so I force it to load the "web"

Rob
  • 26,989
  • 16
  • 82
  • 98
jenlai1345
  • 31
  • 5
0

Swift version answer.

In "AppDelegate.swift" file:

func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey: Any] = [:]) -> Bool {

    FBSDKApplicationDelegate.sharedInstance().application(app, open: url, sourceApplication: options[UIApplicationOpenURLOptionsKey.sourceApplication] as? String, annotation: options[UIApplicationOpenURLOptionsKey.annotation])

    return true
}
Alex Kolovatov
  • 859
  • 7
  • 12