简体   繁体   中英

Check iOS device facebook permissions for my app

I want to check whether permission is given to my app for facebook access in iOS settings so that I can use different flag with openWithBehaviour function of facebook for facebook social login. 1)

FBSessionLoginBehaviorWithNoFallbackToWebView i.e 
    [session openWithBehavior:FBSessionLoginBehaviorWithNoFallbackToWebView
                completionHandler:^(FBSession *session,
                                    FBSessionState status,
                                    NSError *error) {
                    // Respond to session state changes,
                    // ex: updating the view
                    [_self sessionStateChanged:session state:status error:error];
                }];

if permission is not given for my app in iOS settings for facebook and 2)

FBSessionLoginBehaviorUseSystemAccountIfPresent i.e
    [session openWithBehavior:FBSessionLoginBehaviorUseSystemAccountIfPresent
                completionHandler:^(FBSession *session,
                                    FBSessionState status,
                                    NSError *error) {
                    // Respond to session state changes,
                    // ex: updating the view
                    [_self sessionStateChanged:session state:status error:error];
                }]; 

So is it possible to check whether my app is denied permission by the user in settings? Any help, suggestion is deeply appreciated. (I want this because on iOS 6 devices if user has denied permission for my app in iOS facebook settings then facebook login fall back is interrupted).

Why don't you access [FBSession activeSession] before making the call? There is

@property (readonly, copy) NSArray *permissions;

and

@property (readonly) FBSessionState state;

to do checks before making any call for log in on the Facebook SDK. NSArray permissions contains NSStrings so you can easily detect what your session is allowed to do.

I solved this:

[accountStore requestAccessToAccountsWithType:facebookAccountType
                                                  options:options completion:^(BOOL granted, NSError *e) {
                                                      if (granted) {
                                                         NSlog(@"Permission granted");
                                                          // everything is fine i.e, facebook account is created in iOS device settings and permission is given to your app to use facebook information.

                                                          //call facebook login using openWithReadPermissions function of facebook SDK or openWithBehaviour with FBSessionLoginBehaviorWithUseSystemAccountIfPresent

                                                      }
                                                      else
                                                      {
                                                          NSLog(@"Permission     rejected");
                                                          NSLog(@"Facebook error     details: %@",e);

                                                          if ([e code] ==     ACErrorAccountNotFound) {
                                                                  //This means user has not created facebook account in ios settings.

                                                          }
                                                          else if ([e code]== 7 || e==nil){
                                                                  //This means user has denied permission for your app in iOS device facebook settings. So if user tries for social login using facebook then you can call openWithBehaviour facebook SDK function with FBSessionLoginBehaviorWithNoFallbackToWebView to manually give fall facebook fallback.
                                                          }
                                                      }
                                                  }];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM