NSInvalidArgumentException thrown from ACAccountStore when calling [FBSession openActiveSessionWithPermissions…] on iOS 6.0 and iOS 6.0.1

孤人 提交于 2019-12-18 04:02:51

问题


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?


回答1:


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;
}


来源:https://stackoverflow.com/questions/13320624/nsinvalidargumentexception-thrown-from-acaccountstore-when-calling-fbsession-op

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!