Native Facebook app does not open with Facebook login in iOS 9 Native Facebook app does not open with Facebook login in iOS 9 ios ios

Native Facebook app does not open with Facebook login in iOS 9


Below is complete process for new "Facebook login".


this is how I have revised my Facebook Login integration to get it work on latest update.

Xcode 7.x , iOS 9 , Facebook SDK 4.x

Step-1. Download latest Facebook SDK (it includes major changes).

Step-2. Add FBSDKCoreKit.framework and FBSDKLoginKit.framework to your project.

Step-3. Now go to Project > Build Phases > add SafariServices.framework

Step-4. There are three changes in info.plist we need to verify.

4.1 Make sure you have below in your info.plist file

<key>CFBundleURLTypes</key><array>  <dict>  <key>CFBundleURLSchemes</key>  <array>    <string><your fb id here eg. fbxxxxxx></string>  </array>  </dict></array>  <key>FacebookAppID</key>  <string><your FacebookAppID></string>  <key>FacebookDisplayName</key><string><Your_App_Name_Here></string>

4.2 Now add below for White-list Facebook Servers, this is must for iOS 9

<key>NSAppTransportSecurity</key><dict>  <key>NSExceptionDomains</key>  <dict>    <key>facebook.com</key>    <dict>      <key>NSIncludesSubdomains</key>      <true/>      <key>NSExceptionRequiresForwardSecrecy</key>      <false/>    </dict>    <key>fbcdn.net</key>    <dict>      <key>NSIncludesSubdomains</key>      <true/>      <key>NSExceptionRequiresForwardSecrecy</key>      <false/>    </dict>    <key>akamaihd.net</key>    <dict>      <key>NSIncludesSubdomains</key>      <true/>      <key>NSExceptionRequiresForwardSecrecy</key>      <false/>    </dict>  </dict></dict>

4.3 Add URL schemes

<key>LSApplicationQueriesSchemes</key>  <array>      <string>fbapi</string>      <string>fb-messenger-api</string>      <string>fbauth2</string>      <string>fbshareextension</string>  </array>

Step-5. Now open AppDelegate.m file

5.1 Add below import statements, (remove old one).

#import <FBSDKLoginKit/FBSDKLoginKit.h> #import <FBSDKCoreKit/FBSDKCoreKit.h>

5.2 update following following methods

- (BOOL)application:(UIApplication *)application            openURL:(NSURL *)url  sourceApplication:(NSString *)sourceApplication         annotation:(id)annotation {  return [[FBSDKApplicationDelegate sharedInstance] application:application                                                         openURL:url                                               sourceApplication:sourceApplication                                                      annotation:annotation];}- (void)applicationDidBecomeActive:(UIApplication *)application {  [FBSDKAppEvents activateApp];}- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {  return [[FBSDKApplicationDelegate sharedInstance] application:application                                    didFinishLaunchingWithOptions:launchOptions];}

Step-6. Now we need to modify our Login Controller, where we do Login task

6.1 Add these imports in Login ViewController.m

#import <FBSDKCoreKit/FBSDKCoreKit.h>#import <FBSDKLoginKit/FBSDKLoginKit.h>

6.2 Add Facebook Login Button

FBSDKLoginButton *loginButton = [[FBSDKLoginButton alloc] init];loginButton.center = self.view.center;[self.view addSubview:loginButton];

6.3 Handle Login button click

-(IBAction)facebookLogin:(id)sender{    FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];    if ([FBSDKAccessToken currentAccessToken])    {        NSLog(@"Token is available : %@",[[FBSDKAccessToken currentAccessToken]tokenString]);        [self fetchUserInfo];    }    else    {        [login logInWithReadPermissions:@[@"email"] fromViewController:self handler:^(FBSDKLoginManagerLoginResult *result, NSError *error)         {             if (error)             {                 NSLog(@"Login process error");             }             else if (result.isCancelled)             {                 NSLog(@"User cancelled login");             }             else             {                 NSLog(@"Login Success");                 if ([result.grantedPermissions containsObject:@"email"])                 {                     NSLog(@"result is:%@",result);                     [self fetchUserInfo];                 }                 else                 {                     [SVProgressHUD showErrorWithStatus:@"Facebook email permission error"];                 }             }         }];    }}

6.4 Get user info (name, email etc.)

-(void)fetchUserInfo{    if ([FBSDKAccessToken currentAccessToken])    {        NSLog(@"Token is available : %@",[[FBSDKAccessToken currentAccessToken]tokenString]);        [[[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:@{@"fields": @"id, name, email"}]         startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {             if (!error)             {                 NSLog(@"results:%@",result);                 NSString *email = [result objectForKey:@"email"];                 NSString *userId = [result objectForKey:@"id"];                 if (email.length >0 )                 {                     //Start you app Todo                 }                 else                 {                    NSLog(@“Facebook email is not verified");                 }             }             else             {                 NSLog(@"Error %@",error);            }         }];    }}

Step-7. Now you can build project, you should get below screen.

enter image description here

Hope this will help you guys.

References : Thanks to Facebook docs, Stackoverflow posts and Google.


This is by design. Facebook still have some issue with iOS9.

See the Facebook team answere : https://developers.facebook.com/bugs/786729821439894/?search_id Thanks


In the end I changed my Podfile to previous FB version:
From:

pod 'FBSDKCoreKit' pod 'FBSDKLoginKit' pod 'FBSDKShareKit'
TO:

pod 'FBSDKCoreKit','~>4.5.1'pod 'FBSDKLoginKit','~>4.5.1'pod 'FBSDKShareKit','~>4.5.1'

From my point of view Facebook should check last login of the user and based on it trigger the correct Login flow.(and keep the small developers out of "web vs native war").