There are no built-in functions to check for an account. You must access the account as usual, intercept and process the error in the else branch. The type of error is ACErrorCode, and the possible values ββare:
typedef enum ACErrorCode { ACErrorUnknown = 1, ACErrorAccountMissingRequiredProperty, ACErrorAccountAuthenticationFailed, ACErrorAccountTypeInvalid, ACErrorAccountAlreadyExists, ACErrorAccountNotFound, ACErrorPermissionDenied, ACErrorAccessInfoInvalid } ACErrorCode;
So your code might look like this:
-(void)requestBasicPermissionsForFacebookAccount { ACAccountType * facebookAccountType = [self.accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook]; NSArray * permissions = @[@"email"]; NSDictionary * options = @{ACFacebookAppIdKey : kFacebookAppId, ACFacebookPermissionsKey : permissions, ACFacebookAudienceKey : ACFacebookAudienceEveryone}; FacebookAccountManager * fbMgr = [[FacebookAccountManager alloc] init]; [self.accountStore requestAccessToAccountsWithType:facebookAccountType options:options completion:^(BOOL granted, NSError *error) { if (granted) { NSArray * accounts = [self.accountStore accountsWithAccountType:facebookAccountType]; fbMgr.account = [accounts lastObject]; fbMgr.isBasicPermissionsGranted = YES; [self.accountManagers addObject:fbMgr]; NSLog(@"granted!"); } else { fbMgr.account = nil; fbMgr.isBasicPermissionsGranted = NO; switch ([error code]) { case 1: [self showErrorAlertWithMessage:@"Unknown error occured, try again later!"]; break; case 3: [self showErrorAlertWithMessage:@"Authentication failed, try again later!"]; break; case 6: [self showErrorAlertWithMessage:@"Facebook account does not exists. Please create it in Settings and come back!"]; break; case 7: [self showErrorAlertWithMessage:@"Permission request failed. You won't be able to share information to Facebook"]; break; default: break; } NSLog(@"error is: %@", error); } }]; } - (void)showErrorAlertWithMessage:(NSString *)message { dispatch_async(dispatch_get_main_queue(), ^{ UIAlertView * alertView = [[UIAlertView alloc] initWithTitle:@"Error" message:message delegate:self cancelButtonTitle:@"Done" otherButtonTitles:nil]; [alertView show]; }); }
source share