ACAccountStore Error 6 (ACErrorAccountNotFound) and 8

前端 未结 3 1642
离开以前
离开以前 2020-12-14 23:38

I\'m attempting to get an account from ACAccountStore using the following code:

- (void) facebookLoginOnSuccess: (void (^)(void)) successBlock onError:(void(^         


        
相关标签:
3条回答
  • 2020-12-14 23:45

    jAmi has the right idea, but I don't like the idea of the magic numbers in the code. There is an enum that has the numbers built into it (ACErrorCode).

    0 讨论(0)
  • 2020-12-15 00:03

    My own solution was to use Facebook SDK instead of trying with the lib directly and now it's working.

    0 讨论(0)
  • 2020-12-15 00:07

    Ok so if you haven't setup an account from your Settings in iOS 6 it throws error code 6. If the user simply denies permission than it throws error code 7. In case 6 i suggest you ask the user to first setup her account in Settings.

    NSDictionary *options = @{
    ACFacebookAppIdKey: @"1234567890",
    ACFacebookPermissionsKey: @[@"publish_stream"],
    ACFacebookAudienceKey: ACFacebookAudienceFriends
    };
    
    [self.accountStore requestAccessToAccountsWithType:facebookAccountType options:options completion:^(BOOL granted, NSError *error)
    {
        if (granted)
        {
            NSArray *accounts = [self.accountStore accountsWithAccountType:facebookAccountType];
    
            if([accounts count]>0)
                self.facebookAccount = [accounts lastObject];
        }
        else
        {
            dispatch_async(dispatch_get_main_queue(), ^{
    
                // Fail gracefully...
                NSLog(@"%@",error.description);
                if([error code]== ACErrorAccountNotFound)
                    [self throwAlertWithTitle:@"Error" message:@"Account not found. Please setup your account in settings app."];
                else
                    [self throwAlertWithTitle:@"Error" message:@"Account access denied."];
    
            });
        }
    }];
    
    0 讨论(0)
提交回复
热议问题