Continuous closing the login page in facebook, which is integrated with the iOS app.

Mine - iOS app in Objective-C, and an integrated Facebook SDK for login.

I have a controller mainview, where I show my button. Click on the button below the code is executed on the processor buttons.

FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init]; [login logInWithReadPermissions: @[@"public_profile", @"email"] fromViewController:self handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) { if (error) { NSLog(@"Process error %@",error.description); } else if (result.isCancelled) { NSLog(@"Cancelled"); } else { if ([result.grantedPermissions containsObject:kEmail]) { [self fetchfbUserInfo]; } else { NSLog(@"User Declined permissions"); } } }]; 

When the login page to Facebook is displayed in the Web view in our application, if the login page in facebook remains for some time without any changes, it is interrupted by closing with the following error in the console.

FBSDKLog: ERROR: The parent view SFSafariViewController controller was fired. This can happen if you run a login on UIAlertController. Instead, make sure your topmost view controller will not be prematurely dismissed.

I did some reverse engineering, and found that this class method FBSDKApplicationDelegate delegation should be called to the error message.

 - (void)viewControllerDidDisappear:(FBSDKContainerViewController *)viewController animated:(BOOL)animated { if (_safariViewController) { [FBSDKLogger singleShotLogEntry:FBSDKLoggingBehaviorDeveloperErrors logEntry:@"**ERROR**:\n The SFSafariViewController parent view controller was dismissed.\n" "This can happen if you are triggering login from a UIAlertController. Instead, make sure your top most view " "controller will not be prematurely dismissed."]; [self safariViewControllerDidFinish:_safariViewController]; } } *) viewController animated: (BOOL) animated - (void)viewControllerDidDisappear:(FBSDKContainerViewController *)viewController animated:(BOOL)animated { if (_safariViewController) { [FBSDKLogger singleShotLogEntry:FBSDKLoggingBehaviorDeveloperErrors logEntry:@"**ERROR**:\n The SFSafariViewController parent view controller was dismissed.\n" "This can happen if you are triggering login from a UIAlertController. Instead, make sure your top most view " "controller will not be prematurely dismissed."]; [self safariViewControllerDidFinish:_safariViewController]; } } \ n The SFSafariViewController parent view controller was dismissed \ n." - (void)viewControllerDidDisappear:(FBSDKContainerViewController *)viewController animated:(BOOL)animated { if (_safariViewController) { [FBSDKLogger singleShotLogEntry:FBSDKLoggingBehaviorDeveloperErrors logEntry:@"**ERROR**:\n The SFSafariViewController parent view controller was dismissed.\n" "This can happen if you are triggering login from a UIAlertController. Instead, make sure your top most view " "controller will not be prematurely dismissed."]; [self safariViewControllerDidFinish:_safariViewController]; } } login from a UIAlertController. Instead, make sure your top most view" - (void)viewControllerDidDisappear:(FBSDKContainerViewController *)viewController animated:(BOOL)animated { if (_safariViewController) { [FBSDKLogger singleShotLogEntry:FBSDKLoggingBehaviorDeveloperErrors logEntry:@"**ERROR**:\n The SFSafariViewController parent view controller was dismissed.\n" "This can happen if you are triggering login from a UIAlertController. Instead, make sure your top most view " "controller will not be prematurely dismissed."]; [self safariViewControllerDidFinish:_safariViewController]; } } 

Any possible reasons why the login page (login page or application, if you are logged in) closed / rejected it?

+5
source share
1 answer

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.

+2
source

All Articles