The default behavior in the SDK FB iOS with iOS 9 is to use mobile Safari for user authentication (as opposed to self-FOS applications for iOS). When a user tries to log on to your application with Facebook, but never part of Facebook's mobile Safari (no cookie), Safari loads the page on which the user is asked to "Sign in to the Facebook app." Tapping this button brings the user to the FB's own application, which leads to the dismissal of Safari page (and your application moves to the background). In fact, it cancels input and returns to the flow FBSDKLoginManagerLoginResult using isCancelled == true .
When the user accepts the authorization to own FB app and return to your application, application:openURL:options: called with fb<your-fb-app-id>:// url No (which contains an access token). According to the rules of the entrance to the FB SDK system, the URL-address must be submitted as follows:
[[FBSDKApplicationDelegate sharedInstance] application:application openURL:url options:options];
However FBSDKApplicationDelegate simply ignores the url and returns NO , because the input stream has been "canceled" in advance.
To me it looks like a serious error in FB SDK.
The only workaround I have found for this problem is the following:
- (BOOL) application:(UIApplication*)application openURL:(nonnull NSURL *)url options:(nonnull NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options { BOOL handled = [[FBSDKApplicationDelegate sharedInstance] application:application openURL:url options:options]; if (!handled) { NSMutableDictionary *launchOptions = [NSMutableDictionary new]; launchOptions[UIApplicationLaunchOptionsSourceApplicationKey] = options[UIApplicationOpenURLOptionsSourceApplicationKey]; launchOptions[UIApplicationLaunchOptionsAnnotationKey] = options[UIApplicationOpenURLOptionsAnnotationKey]; launchOptions[UIApplicationLaunchOptionsURLKey] = url; return [[FBSDKApplicationDelegate sharedInstance] application:application didFinishLaunchingWithOptions:launchOptions]; } return handled; } *) application openURL: (nonnull NSURL *) url options: (nonnull NSDictionary <UIApplicationOpenURLOptionsKey, id> *) options - (BOOL) application:(UIApplication*)application openURL:(nonnull NSURL *)url options:(nonnull NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options { BOOL handled = [[FBSDKApplicationDelegate sharedInstance] application:application openURL:url options:options]; if (!handled) { NSMutableDictionary *launchOptions = [NSMutableDictionary new]; launchOptions[UIApplicationLaunchOptionsSourceApplicationKey] = options[UIApplicationOpenURLOptionsSourceApplicationKey]; launchOptions[UIApplicationLaunchOptionsAnnotationKey] = options[UIApplicationOpenURLOptionsAnnotationKey]; launchOptions[UIApplicationLaunchOptionsURLKey] = url; return [[FBSDKApplicationDelegate sharedInstance] application:application didFinishLaunchingWithOptions:launchOptions]; } return handled; } application: application openURL: url options: options]; - (BOOL) application:(UIApplication*)application openURL:(nonnull NSURL *)url options:(nonnull NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options { BOOL handled = [[FBSDKApplicationDelegate sharedInstance] application:application openURL:url options:options]; if (!handled) { NSMutableDictionary *launchOptions = [NSMutableDictionary new]; launchOptions[UIApplicationLaunchOptionsSourceApplicationKey] = options[UIApplicationOpenURLOptionsSourceApplicationKey]; launchOptions[UIApplicationLaunchOptionsAnnotationKey] = options[UIApplicationOpenURLOptionsAnnotationKey]; launchOptions[UIApplicationLaunchOptionsURLKey] = url; return [[FBSDKApplicationDelegate sharedInstance] application:application didFinishLaunchingWithOptions:launchOptions]; } return handled; } ; - (BOOL) application:(UIApplication*)application openURL:(nonnull NSURL *)url options:(nonnull NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options { BOOL handled = [[FBSDKApplicationDelegate sharedInstance] application:application openURL:url options:options]; if (!handled) { NSMutableDictionary *launchOptions = [NSMutableDictionary new]; launchOptions[UIApplicationLaunchOptionsSourceApplicationKey] = options[UIApplicationOpenURLOptionsSourceApplicationKey]; launchOptions[UIApplicationLaunchOptionsAnnotationKey] = options[UIApplicationOpenURLOptionsAnnotationKey]; launchOptions[UIApplicationLaunchOptionsURLKey] = url; return [[FBSDKApplicationDelegate sharedInstance] application:application didFinishLaunchingWithOptions:launchOptions]; } return handled; } ]; - (BOOL) application:(UIApplication*)application openURL:(nonnull NSURL *)url options:(nonnull NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options { BOOL handled = [[FBSDKApplicationDelegate sharedInstance] application:application openURL:url options:options]; if (!handled) { NSMutableDictionary *launchOptions = [NSMutableDictionary new]; launchOptions[UIApplicationLaunchOptionsSourceApplicationKey] = options[UIApplicationOpenURLOptionsSourceApplicationKey]; launchOptions[UIApplicationLaunchOptionsAnnotationKey] = options[UIApplicationOpenURLOptionsAnnotationKey]; launchOptions[UIApplicationLaunchOptionsURLKey] = url; return [[FBSDKApplicationDelegate sharedInstance] application:application didFinishLaunchingWithOptions:launchOptions]; } return handled; } ]; - (BOOL) application:(UIApplication*)application openURL:(nonnull NSURL *)url options:(nonnull NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options { BOOL handled = [[FBSDKApplicationDelegate sharedInstance] application:application openURL:url options:options]; if (!handled) { NSMutableDictionary *launchOptions = [NSMutableDictionary new]; launchOptions[UIApplicationLaunchOptionsSourceApplicationKey] = options[UIApplicationOpenURLOptionsSourceApplicationKey]; launchOptions[UIApplicationLaunchOptionsAnnotationKey] = options[UIApplicationOpenURLOptionsAnnotationKey]; launchOptions[UIApplicationLaunchOptionsURLKey] = url; return [[FBSDKApplicationDelegate sharedInstance] application:application didFinishLaunchingWithOptions:launchOptions]; } return handled; }
The above will actually store the access token inside the FB SDK.
To continue with the input stream in, you can see a notice FBSDKAccessTokenDidChange , which will be called after processing the URL-addresses FB above.
source share