4

I was following Facebook's own tutorial for FB login in iOS (Objective-C) but every time I log in - after the initial permission authorization screen - I'm getting the infamous "You have already authorized this app" webview.

I've read a ton of posts but I haven't been able to sort it out, hence the (re)post. I find this rather odd because the app has absolutely nothing except the boilerplate login code. This behaviour happens in both Simulator and real devices.

Can't seem to shake this webview out of the way

This app is for iOS 9.0 and I am using FBSDK 4.7.1 (installed via CocoaPods):

pod 'FBSDKLoginKit', '~> 4.6'

The code itself is pretty boilerplate stuff, here's my AppDelegate.m:

#import "AppDelegate.h"
#import <FBSDKCoreKit/FBSDKCoreKit.h>

@interface AppDelegate ()

@end

@implementation AppDelegate

- (void)applicationDidBecomeActive:(UIApplication *)application {
    [FBSDKAppEvents activateApp];
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    [[FBSDKApplicationDelegate sharedInstance] application:application
                             didFinishLaunchingWithOptions:launchOptions];
    return YES;
}

- (BOOL)application:(UIApplication *)application
            openURL:(NSURL *)url
  sourceApplication:(NSString *)sourceApplication
         annotation:(id)annotation {
    return [[FBSDKApplicationDelegate sharedInstance] application:application
                                                          openURL:url
                                                sourceApplication:sourceApplication
                                                       annotation:annotation];
}
@end

and my ViewController.m:

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

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    FBSDKLoginButton *loginButton = [[FBSDKLoginButton alloc] init];
    loginButton.readPermissions = @[@"public_profile", @"email", @"user_friends"];
    [loginButton setLoginBehavior:FBSDKLoginBehaviorSystemAccount]; // No difference

    loginButton.center = self.view.center;
    [self.view addSubview:loginButton];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

And a screenshot of the Info.plist:

Info.plist

Finally, I'm also getting these two errors in the console:

2015-11-24 11:50:42.855 lixo[26941:389756] -canOpenURL: failed for URL: "fbauth2:/" - error: "(null)"
2015-11-24 11:50:42.860 lixo[26941:389756] -canOpenURL: failed for URL: "fbauth2:/" - error: "(null)"

Although from what I've read this can be safely ignored if LSApplicationQueriesSchemes is set in the Info.plist.

Any ideas how to avoid this?

João Pereira
  • 3,545
  • 7
  • 44
  • 53
  • What exactly is the problem? Unless you are getting that screen the very first time you're trying to log in, it's telling you what your status is. – Avi Nov 24 '15 at 12:10
  • It hapened to me also. Because you always logged in safari when you open permission dialog first time. Open safari and go to facebook.com ,you will be logged in there just logout from there . – Muhammad Zohaib Ehsan Nov 24 '15 at 12:11
  • 1
    @Avi: The problem is the user seeing that annoying webview everytime he wants to login. We support Facebook integration precisely because we want to keep the login process as straightforward and fast as possible. Nobody likes typing passwords nor seeing popups all the time. – João Pereira Nov 24 '15 at 14:10
  • I have the same problem and this answer help me: http://stackoverflow.com/questions/32299271/facebook-sdk-login-never-calls-back-my-application-on-ios-9/32300235#32300235 – never May 06 '16 at 12:18
  • Any progress here? I'm facing the same problem and it's really annoying... – fillky Nov 08 '16 at 21:06
  • @fillky it really is the default behaviour. The only solution at hand would be to use an older version of Facebook's SDK I believe. – João Pereira Nov 13 '16 at 12:02

3 Answers3

0

Instead of triggering a login on every launch, you can check the status of the access token. If it's not expired, you skip login, and just start using the API. The following method can be used to check if the token is expired:

+(BOOL) accessTokenIsLocalyValid
{
    return [FBSDKAccessToken currentAccessToken] && [[NSDate date] compare:[FBSDKAccessToken currentAccessToken].expirationDate] == NSOrderedAscending;
}

If you have a valid token, you can refresh it using [FBSDKAccessToken refreshCurrentAccessToken:].

Avi
  • 7,469
  • 2
  • 21
  • 22
  • I understand what you're saying but it really doesn't solve the issue because when I don't have a token I'll still have to login and I'll still get that webview. Your method works nevertheless. – João Pereira Nov 24 '15 at 14:24
  • If you don't have a token, you haven't logged in. I don't understand what you expect to do in that situation. – Avi Nov 24 '15 at 18:15
  • 2
    I expected the user to click the "login with facebook" button, not see that webview with that (useless) message and return to the app, like the Fast App Switch workflow that older SDKs used. – João Pereira Nov 25 '15 at 09:48
0

Check if there is a current session before logging in with FBSDKLoginManager.

if ([FBSDKAccessToken currentAccessToken]) 
 {
      NSLog(@"Token is available : %@",[[FBSDKAccessToken currentAccessToken]tokenString]);
      // Now get details using graphpath. 
 } else {
     // login with permissions using FBSDKLoginManager and get details using graphpath in completion

 }
Amal T S
  • 3,327
  • 2
  • 24
  • 57
-1

This is the default behaviour!

Facebook SDK allows you to login to facebook from Facebook App (if it is installed in your phone), OR else it will manage the login from Safari. And when Facebook login is used by your application from Safari, this is how you have to accept permission everytime.

Another behaviour is that If your iphone doesnt have Facebook App, and you use Facebook SDK login process from your application, it will use Safari; you wont be able to logout even, as Safari saves your credentials in cookies and there is no way by which you can clear safari cookies from your application.

If your phone has Facebook App, it will redirect to your application without any interruptions as such.

EDIT -

This behaviour is also found in iOS 10. Thanks for the edit - Tiois

Community
  • 1
  • 1
Saheb Roy
  • 5,899
  • 3
  • 23
  • 35