I\'m attempting to get an account from ACAccountStore using the following code:
- (void) facebookLoginOnSuccess: (void (^)(void)) successBlock onError:(void(^
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).
My own solution was to use Facebook SDK instead of trying with the lib directly and now it's working.
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."];
});
}
}];