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

I upgraded the iPhone 6 plus to the beta version of iOS 9 and tried to log in to Facebook, but every time he presented a UIWebView with a Facebook login form.

I have facebook sdk

FB_IOS_SDK_VERSION_STRING @"3.24.0" FB_IOS_SDK_TARGET_PLATFORM_VERSION @"v2.2" 

And I use the following methods to log in to Facebook

  NSArray *permissions = @[@"email",@"user_birthday",@"public_profile"]; FBSessionStateHandler completionHandler = ^(FBSession *session, FBSessionState status, NSError *error) { [self sessionStateChanged:session state:status error:error]; }; if ([FBSession activeSession].state == FBSessionStateCreatedTokenLoaded) { // we have a cached token, so open the session [[FBSession activeSession]openWithBehavior:FBSessionLoginBehaviorUseSystemAccountIfPresent fromViewController:nil completionHandler:completionHandler]; } else { [self clearAllUserInfo]; [[NSURLCache sharedURLCache] removeAllCachedResponses]; // create a new facebook session FBSession *fbSession = [[FBSession alloc] initWithPermissions:permissions]; [FBSession setActiveSession:fbSession]; [fbSession openWithBehavior:FBSessionLoginBehaviorUseSystemAccountIfPresent fromViewController:nil completionHandler:completionHandler]; } 

I have the following setting in plist file

  <key>LSApplicationQueriesSchemes</key> <array> <string>fbapi</string> <string>fbapi20130214</string> <string>fbapi20130410</string> <string>fbapi20130702</string> <string>fbapi20131010</string> <string>fbapi20131219</string> <string>fbapi20140410</string> <string>fbapi20140116</string> <string>fbapi20150313</string> <string>fbapi20150629</string> <string>fb-messenger-api20140430</string> <string>fbauth</string> <string>fbauth2</string> <array> 

Please let me know what I'm missing here. First he checks the iPhone device Setting-> Facebook credentials , but never opens the Facebook application for login. It does not seem to recognize the Facebook application installed on the device.

+52
ios objective-c facebook ios9 facebook-login
Sep 14 '15 at 13:59 on
source share
12 answers

The following is the complete process for a new Facebook login.




Here's how I reworked my Facebook integration to make it work with the latest update.

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

Step 1. Download the latest version of the SDK for Facebook (it includes significant 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 to the info.plist file .

4.1 Make sure that you specify below in the 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 necessary 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 Adding URL Schemas

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

Step 5. Now open the file AppDelegate.m

5.1 Add the import statements below (delete the old one).

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

5.2 update after the 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 change our login controller, where we perform the login task

6.1 Add these imports to 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 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 information (name, email address, 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 create a project, you should get below the screen.

enter image description here

Hope this helps you guys.

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

+53
Oct 07 '15 at 16:54
source share

This is by design. Facebook still has some problems with iOS9.

See the Facebook team: https://developers.facebook.com/bugs/786729821439894/?search_id Thank you

+33
Sep 15 '15 at 18:25
source share

In the end, I changed my subfile to the previous version of FB:
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 the last user login and, based on this, call the correct login stream. (and to prevent small developers from falling into the "network against the native war").

+10
Oct 12 '15 at 10:32
source share

@dan is right. To provide a better experience for users on iOS 9, the new SDK automatically determines the best input stream. If you are running iOS 8 or earlier, an app switcher will still be preferable.

+4
Sep 14 '15 at 16:22
source share

Safari View Controller is used by default in the Facebook SDK. For those of you who want to return to your previous experience, see below. It works only for SDK 3.x, it will not work on 4.x.

If you want the v3.x SDK (tested on v3.24.1) to work as before (without opening the Safari View Controller and instead switching to the application instead), call this code somewhere at the beginning of the application, for example. didFinishLaunchingWithOptions:

 SEL useSafariSel = sel_getUid("useSafariViewControllerForDialogName:"); SEL useNativeSel = sel_getUid("useNativeDialogForDialogName:"); Class FBDialogConfigClass = NSClassFromString(@"FBDialogConfig"); Method useSafariMethod = class_getClassMethod(FBDialogConfigClass, useSafariSel); Method useNativeMethod = class_getClassMethod(FBDialogConfigClass, useNativeSel); IMP returnNO = imp_implementationWithBlock(^BOOL(id me, id dialogName) { return NO; }); method_setImplementation(useSafariMethod, returnNO); IMP returnYES = imp_implementationWithBlock(^BOOL(id me, id dialogName) { return YES; }); method_setImplementation(useNativeMethod, returnYES); 

It runs two methods from FBDialogConfig.

Remember to import the objc / runtime.h header:

 #import <objc/runtime.h> 

@SimonCross Some people simply do not want to understand that Safari View Controller provides a better user interface - they think or know for sure that their users did not log into Facebook in Safari, but they probably logged in to the Facebook application.

+4
Nov 23 '15 at 16:24
source share

After installing all the necessary .plist keys, as indicated in this column, I used the following solution to get out of the registration problem.

 var fbLoginManager : FBSDKLoginManager = FBSDKLoginManager() fbLoginManager.loginBehavior = FBSDKLoginBehavior.Web 

So that it is always included in the application.

+3
Jan 11 '16 at 9:44
source share

With the release of iOS 9, Apple has made some significant changes to app switching. This has affected iOS 9 apps integrated with Facebook. Most people will notice this in their experience using Facebook Login. In applications that use the latest SDK (v4.6 and v3.24), we will process the stream using Safari View Controller (SVC) instead of quickly switching applications (FAS) due to additional inter-page dialog boxes that add additional steps to the process logging in to the FAS system on iOS 9. In addition, the data we saw from more than 250 applications show that this is the best experience for people in the long run. Please read more. https://developers.facebook.com/blog/post/2015/10/29/Facebook-Login-iOS9

+2
Mar 02 '16 at 13:55
source share

Facebook has changed Facebook login behavior for iOS9.

Here is a quote from a Facebook blog post :

We tracked data and CTR for more than 250 applications over the last 6 weeks since the launch of iOS 9. The click-through rate (CTR) in SVC Login exceeds the CTR of the entry in the switch application and improves with 3 times the speed of the switch application. This indicates that the SVC experience is better for people and developers today, and is likely to be the best solution in the long run. For this reason, the latest Facebook SDK for iOS uses SVC as the default login experience.

+2
Oct. 27 '16 at 15:26
source share

It worked for me. Add this to your .plist .

 <key>LSApplicationQueriesSchemes</key> <array> <string>fb</string> </array> 

For iOS9, we need to add a key to our .plist for URL schemes.

+1
Oct. 16 '15 at 7:33
source share

I know that he is old. But you can put this code in your application:(UIApplication *)application didFinishLaunchingWithOptions:

 SEL useNativeSel = sel_getUid("useNativeDialogForDialogName:"); Class FBSDKServerConfiguration = NSClassFromString(@"FBSDKServerConfiguration"); Method useNativeMethod = class_getInstanceMethod(FBSDKServerConfiguration, useNativeSel); IMP returnYES = imp_implementationWithBlock(^BOOL(id me, id dialogName) { return YES; }); method_setImplementation(useNativeMethod, returnYES); 

And FacebookSDK will enter through its own application when the application is installed instead of the browser.

+1
Jul 26 '16 at 9:32
source share

Putting this in appdelegate, I solved the problem

 func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool { return FBSDKApplicationDelegate.sharedInstance().application(app, open: url, sourceApplication: options[UIApplicationOpenURLOptionsKey.sourceApplication] as! String, annotation: options[UIApplicationOpenURLOptionsKey.annotation]) } 
0
Nov 01 '16 at 8:52
source share

Adding below lines to the .plist file helped me:

 <key>LSApplicationQueriesSchemes</key> <array> <string>fbapi</string> <string>fbapi20130214</string> <string>fbapi20130410</string> <string>fbapi20130702</string> <string>fbapi20131010</string> <string>fbapi20131219</string> <string>fbapi20140410</string> <string>fbapi20140116</string> <string>fbapi20150313</string> <string>fbapi20150629</string> <string>fbauth</string> <string>fbauth2</string> <string>fb-messenger-api20140430</string> </array> 
-3
Nov 21 '15 at 11:18
source share



All Articles