The built-in Facebook login does not open the facebook application, even if it is installed on the device?

I followed every step described in the documents facebook-iso-sdk 4.8.0 for iOS 9, but still could not pre-configure the application to "login-with-facebook" in my application, even if the facebook application was already installed.

As you can see in the screenshot below, I modified info.plist, but still cannot get my own application switch to work.

I also double-checked typo errors in the info.plist value. and I can assure you that they are true.

Here is my code: -

if (![AppDelegate SharedInstance].login) { [AppDelegate SharedInstance].login = [[FBSDKLoginManager alloc] init]; } [AppDelegate SharedInstance].login.loginBehavior = FBSDKLoginBehaviorNative; [[AppDelegate SharedInstance].login logInWithReadPermissions:@[@"public_profile",@"email",@"user_friends"] fromViewController:self handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) { if (error) { } else if (result.isCancelled) { // Handle cancellations } else { NSLog(@"result.grantedPermissions == %@",result.grantedPermissions); if (result.token) { [[[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:@{@"fields": @"id, name, email, first_name, last_name"}] startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) { if (!error) { NSLog(@"fetched user:%@", result); NSString *userImageURL = [NSString stringWithFormat:@"https://graph.facebook.com/%@/picture?type=large", [result objectForKey:@"id"]]; [dictFacebookDetail addEntriesFromDictionary:result]; [dictFacebookDetail setObject:userImageURL forKey:@"profilepic"]; NSLog(@"facebook login result --- %@",dictFacebookDetail); [self performSelectorInBackground:@selector(CheckFacebookUser:) withObject:dictFacebookDetail]; } }]; } } }]; 

What am I missing?

Screenshot from info.plist

+6
source share
4 answers

I found a solution, but you have to change something in the FBSDKLogin module. I was debugging Pod, and I realized that Facebook is asking in the FBSDKServerConfiguration class to configure the server for the application. It returns JSON with some information to configure Pod for our application. I realized that by default JSON returns this dictionary:

  "ios_sdk_dialog_flows" = { default = { "use_native_flow" = 0; "use_safari_vc" = 1; }; message = { "use_native_flow" = 1; }; }; 

By default, use_native_flow is 0, so when it saves information in userDefaults to launch the next application. So, when the application calls the FBSDKLoginMananger login method and checks the loginBehaviour in this method, the useNativeDialog variable returns NO. Thus, the switch uses the following case. case FBSDKLoginBehaviorBrowser:

 - (void)logInWithBehavior:(FBSDKLoginBehavior)loginBehavior { . . ... switch (loginBehavior) { case FBSDKLoginBehaviorNative: { if ([FBSDKInternalUtility isFacebookAppInstalled]) { [FBSDKServerConfigurationManager loadServerConfigurationWithCompletionBlock:^(FBSDKServerConfiguration *serverConfiguration, NSError *loadError) { BOOL useNativeDialog = [serverConfiguration useNativeDialogForDialogName:FBSDKDialogConfigurationNameLogin]; if (useNativeDialog && loadError == nil) { [self performNativeLogInWithParameters:loginParams handler:^(BOOL openedURL, NSError *openedURLError) { if (openedURLError) { [FBSDKLogger singleShotLogEntry:FBSDKLoggingBehaviorDeveloperErrors formatString:@"FBSDKLoginBehaviorNative failed : %@\nTrying FBSDKLoginBehaviorBrowser", openedURLError]; } if (openedURL) { completion(YES, FBSDKLoginManagerLoggerAuthMethod_Native, openedURLError); } else { [self logInWithBehavior:FBSDKLoginBehaviorBrowser]; } }]; } else { [self logInWithBehavior:FBSDKLoginBehaviorBrowser]; } }]; break; } // intentional fall through. } case FBSDKLoginBehaviorBrowser: { . . . } 

As we see in the code, we know if the application is installed in this case, if, if ([FBSDKInternalUtility isFacebookAppInstalled]) . To solve the problem, I changed this line

 BOOL useNativeDialog = [serverConfiguration useNativeDialogForDialogName:FBSDKDialogConfigurationNameLogin]; 

to

  BOOL useNativeDialog = YES; 

I know that this is not a good practice, and that will change if I update this Pod, but at least it works, and I need it now. I think we can change this configuration on the facebook developer admin site, but I did not find anything.

+9
source

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 entrance to 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.

+8
source
 typedef NS_ENUM(NSUInteger, FBSDKLoginBehavior) { /*! @abstract This is the default behavior, and indicates logging in through the native Facebook app may be used. The SDK may still use Safari instead. */ FBSDKLoginBehaviorNative = 0, /*! @abstract Attempts log in through the Safari or SFSafariViewController, if available. */ FBSDKLoginBehaviorBrowser, /*! @abstract Attempts log in through the Facebook account currently signed in through the device Settings. @note If the account is not available to the app (either not configured by user or as determined by the SDK) this behavior falls back to \c FBSDKLoginBehaviorNative. */ FBSDKLoginBehaviorSystemAccount, /*! @abstract Attemps log in through a modal \c UIWebView pop up @note This behavior is only available to certain types of apps. Please check the Facebook Platform Policy to verify your app meets the restrictions. */ FBSDKLoginBehaviorWeb, }; 

There are many ways to access the fb login.try file using the alternative option that you prefer.

 FBSDKLoginManager *loginmanager = [[FBSDKLoginManager alloc] init]; loginmanager.loginBehavior=FBSDKLoginBehaviorNative; 

Like this ... hope this helps you :)

+1
source
  • (FBSDKServerConfiguration *) _ defaultServerConfigurationForAppID: (NSString *) appID {// Use the default configuration until we have a configuration from the server. This allows us to set // default values ​​for any of the sets of dialogs or everything else in a centralized location while we wait // for the server to respond. static FBSDKServerConfiguration * _defaultServerConfiguration = nil; if (! [_ defaultServerConfiguration.appID isEqualToString: appID]) { // Bypass native message flow for iOS 9+, as it creates a number of additional confirmation dialogs that lead to // additional friction, which is undesirable. NSOperatingSystemVersion iOS9Version = {.majorVersion = 9, .minorVersion = 0, .patchVersion = 0};
+1
source

All Articles