Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
561 views
in Technique[技术] by (71.8m points)

ios6 - NSInvalidArgumentException thrown from ACAccountStore when calling [FBSession openActiveSessionWithPermissions...] on iOS 6.0 and iOS 6.0.1

With Facebook iOS SDK 3.1.1, I'm performing login using this call -

NSArray *permissions = [[NSArray alloc] initWithObjects: @"email", @"user_birthday", @"user_location", nil];

@try {
    return [FBSession openActiveSessionWithReadPermissions:permissions
                                              allowLoginUI:allowLoginUI
                                         completionHandler:^(FBSession *session,
                                                             FBSessionState state,
                                                             NSError *error) {
                                             [self sessionStateChanged:session
                                                                 state:state
                                                                 error:error];
                                         }];
}
@catch { ... }

There are rare cases when this method throws NSInvalidArgumentException with message Access options are not permitted for this account type. The options argument must be nil., this is thrown from [ACAccountStore requestAccessToAccountsWithType:options:completion:].

Checking the Apple's docs of ACAccountStore, I see this comment for that method:

"Certain account types (such as Facebook) require an options dictionary. This method will throw an NSInvalidArgumentException if the options dictionary is not provided for such account types. Conversely, if the account type does not require an options dictionary, the options parameter must be nil."

Apple require this to be nil except for Facebook, but this method IS called from Facebook, so Maybe this is a bug - either at Facebook or at iOS 6.0/.1, but I couldn't find anything on the web about this issue.

Any ideas?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I found a work around for this bug. Note that the bug is described here as well: https://developers.facebook.com/bugs/139251032898548

The Facebook SDK does not do a null check for return value of accountTypeWithAccountTypeIdentifier. See https://github.com/facebook/facebook-ios-sdk/blob/master/src/FBSystemAccountStoreAdapter.m?source=c#L176

To work around the problem, you can do the following check before attempting facebook lgoin:

if ([[[ACAccountStore alloc]init] accountTypeWithAccountTypeIdentifier:@"com.apple.facebook"] == nil) {
   NSLog(@"Cannot proceed, not facebook account type identifier");
   return;
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...