Search code examples
authenticationios9facebook-ios-sdk

iOS - Facebook SDK v3.24.1 Login Screen is Blank except when using FBSessionLoginBehaviorForcingWebView


I am trying to update my app to use the iOS 9 compatible Facebook SDK v3.24.1. We have not upgrade to v4.x yet, and can not do that just yet so I need to use v3.24.1. I have followed this Facebook Migration Guide: developers.facebook.com/docs/ios/ios9

I have added all the appropriate Facebook settings to my .plist file (i.e. CFBundleURLSchemes, FacebookAppID, FacebookDisplayName, etc).

I have also updated the .plist for the iOS 9 requirements:

<key>NSAppTransportSecurity</key>
<dict>
    <key>NSAllowsArbitraryLoads</key>
    <true/>
</dict>

I have updated the framework files and modified the Facebook login method to now use:

[[FBSession activeSession] openWithBehavior:FBSessionLoginBehaviorWithFallbackToWebView fromViewController:fromViewController completionHandler:handler];

The problem I have is that if I try to use any of the 'behaviors' other than 'FBSessionLoginBehaviorForcingWebView', all I get is a blank white modal screen (below). I really need to allow the app to attempt to authenticate using the iOS Native Facebook Settings or Facebook App before falling back to a web view.

Any suggestions?

enter image description here

Using 'FBSessionLoginBehaviorForcingWebView' does give me the proper web view modal:

enter image description here


Solution

  • This is a bug in Apple's SafariViewController.

    When you use a UIImageRenderingModeAlwaysTemplate UIImage in [UIBarButtonItem appearance] setBackgroundImage: and try to display a SFSafariViewController, you'll only get a blank page.

    UIImage *image = [[UIImage imageNamed:@"someimage"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
    [[UIBarButtonItem appearance] setBackgroundImage:image forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
    

    Using normal UIImage will display SFSafariViewController.