IOS Facebook SDK 3.1 openActiveSessionWithReadPermissions: detection when the user does not provide access

I need to know when a user did not give Facebook access to my application during openActiveSessionWithReadPermissions. (It is not indicated that the switch is set to "OFF" in the "Settings"> "Facebook-> My Application" section.)

Here is the error, if not provided:

Domain error = com.facebook.sdk Code = 2 "The operation could not be completed (com.facebook.sdk 2 error.)" UserInfo = 0x1fd46780 {com.facebook.sdk: ErrorLoginFailedReason = com.facebook.sdk: ErrorLoginFailedReason}

For comparison: there is no error for the network:

Domain error = com.facebook.sdk Code = 2 "Operation could not be performed. (Com.facebook.sdk error 2.)" UserInfo = 0x1edf2eb0 {com.facebook.sdk: ErrorLoginFailedReason = com.facebook.sdk: ErrorLoginFailedReason, com .facebook.sdk: ErrorInnerErrorKey = Domain Error = NSURLErrorDomain Code = -1009 "Internet connection disconnected." UserInfo = 0x1ed47a20 {NSErrorFailingURLKey = https://api.facebook.com/method/auth.iosauthorizeapp, NSErrorFailingURLStringKey = https://api.facebook.com/method/auth.iosauthorizeapp, NSLocalizedDescription = Internet connection disconnected. }}

Is there a safe way to detect when a user is not provided? Am I just looking for error code 2 and one key / value pair in the UserInfo dictionary?

I would like Facebook to give us BOOL granted , as in ACAccountStoreRequestAccessCompletionHandler .

+4
source share
2 answers

@ peter-warbo: I did not find a good solution. I use this:

 [FBSession openActiveSessionWithReadPermissions:FACEBOOK_READ allowLoginUI:YES completionHandler:^(FBSession *session, FBSessionState state, NSError *error) { // find error for not granted if(error && error.code == 2) { NSDictionary *userInfo = error.userInfo; if(userInfo && userInfo.count == 1) { [self fallbackLogin]; return; } } [self sessionStateChanged:session state:state error:error]; }]; - (void)fallbackLogin { // use deprecated [FBSession openActiveSessionWithPermissions:FACEBOOK_READ allowLoginUI:YES completionHandler:^(FBSession *session, FBSessionState state, NSError *error) { [self sessionStateChanged:session state:state error:error]; }]; } 
0
source

You can check permissions with this code:

 - (void)checkForPermissions { // We will request the user public profile and the user birthday // These are the permissions we need: NSArray *permissionsNeeded = @[@"basic_info", @"email"]; // Request the permissions the user currently has [FBRequestConnection startWithGraphPath:@"/me/permissions" completionHandler:^(FBRequestConnection *connection, id result, NSError *error) { //If there is error, handle it accordingly. //Results contains all the permissions user has granted the app. //If you do not have the desired permissions, reauthorize the app // Ask for the missing permissions //requestPermissions = array of permissions to be asked [FBSession.activeSession requestNewReadPermissions:requestPermissions completionHandler:^(FBSession *session, NSError *error) { //Handle the session object as per your requirements. }]; }]; } 

Hope this helps.

0
source

All Articles