Facebook Connect SSO does not work on some iPhone

I implemented FBConnect SSO in my iphone application according to this tutorial. I have tested it on two phones so far, one of which allows me to use the function just fine, while the other phone just opens the Facebook application and immediately closes it. I can establish a valid session, but the dialog seems to just close me on one of them.
What could be the problem? Any help is greatly appreciated.

+6
source share
3 answers

I think your problem is that you do not have the proper configuration either on the client side (in the application) or on the server side (setting up the FB application). Please check both things as follows:

Client application:

Make sure you enter the correct FBAppId in your Info.plist as a URL handler. Facebook will try to open the application using this handler, and if it does not work, your application will not be open.

Plist config

(replace XXXXXXXXXX your FB application)

Check if your application (in the appDelegate application) handles the added custom URL:

 - (BOOL)handleOpenURL:(NSURL*)url { NSString* scheme = [url scheme]; NSString* prefix = [NSString stringWithFormat:@"fb%@", facebookAppId]; if ([scheme hasPrefix:prefix]) { return [fb handleOpenURL:url]; } return YES; } - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation { return [self handleOpenURL:url]; } - (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url { return [self handleOpenURL:url]; } 

Server side

Make sure you configure your package correctly on the FB configuration page. You can check this at https://developers.facebook.com/apps by selecting the application and then in the edit panel:

Fb config

If you have something correctly configured, it should work anyway (with FBapp installed or based on Safari).

+3
source

I saw this with the 3.0 SDK. The reason this happens is because facebook caches access tokens. Access tokens are cached both in the application and in the facebook application on the device (at least conceptually).

If the first time you run the application on the device, facebook will not have a valid access token cached in your application. However, it may still have a valid access token in the facebook application for your application. If he finds one on the facebook side, he does not need to prompt the user again, so a dialog box will appear, then it will disappear and send back the access token. The access token is then cached in your application.

If you restart the application (without deleting it), you will not see the login dialog, as the access token is now cached in your application. If you uninstall your application on the device and log in again, you will see the same behavior if facebook can find the cache key on the side.

I found a solution to this problem. Here is a sample code:

 if (![FBSession activeSession].isOpen) { FBSession *session = [[FBSession alloc] initWithAppID:nil permissions:permissions defaultAudience:FBSessionDefaultAudienceEveryone urlSchemeSuffix:nil tokenCacheStrategy:nil]; [FBSession setActiveSession:session]; [session openWithBehavior:FBSessionLoginBehaviorUseSystemAccountIfPresent completionHandler:^(FBSession *session, FBSessionState status, NSError *error) { // NOTE openActiveSessionWithPermissions causes the facebook app to hang with a blank dialog if my app is installed, authed, and then reinstalled. openWithBehavior // does not. I think it has something to do with the FBSession activeSession. // [FBSession openActiveSessionWithPermissions:self.permissions allowLoginUI:YES completionHandler:^(FBSession *session, FBSessionState status, NSError *error) { switch (status) { case FBSessionStateOpen: [self getFacebookUser]; break; case FBSessionStateClosed: [self fbSessionClosed]; break; case FBSessionStateCreated: [self fbSessionCreated]; break; case FBSessionStateCreatedOpening: [self fbSessionOpening]; break; case FBSessionStateClosedLoginFailed: [self fbSessionClosedLoginFailed]; break; case FBSessionStateOpenTokenExtended: [self fbSessionOpenTokenExtended]; break; case FBSessionStateCreatedTokenLoaded: [self fbSessionCreatedTokenLoaded]; break; } }]; } } 

openActiveSessionWithPermissions causes problems, but openWithBehavior does not. openActiveSession makes the same openWithBehavior call, but I think the setup time of the active session is different and therefore does not work. If I establish an active session before calling openWithBehavior, everything works fine. As for your application and the end user, everything is the same.

+3
source

You need to insert the appropriate log into your code, publish the code and publish which logs are produced in work and failures.

To make a log (see here for more complex methods):

 NSLog(@"My log text"); 

At a minimum, you need to add logs to all callbacks from the Facebook API (even those that you don’t use), and to the handleOpenURL and openUrl methods in the application’s deletion.

Your logs will appear in the Console in Xcode Organizer when you connect the device with which you are testing - this should show you what is happening.

FYI, the Facebook SDK, will first try to use its own application, if installed, otherwise it will launch the Safari browser to request authorization via the Facebook web version.

You should double-check the configuration of your Facebook URL scheme as described in Angel Garcia Olloki's answer.

+1
source

Source: https://habr.com/ru/post/921817/


All Articles