ios – ACAccountStore错误6(ACErrorAccountNotFound)和8

前端之家收集整理的这篇文章主要介绍了ios – ACAccountStore错误6(ACErrorAccountNotFound)和8前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我试图使用以下代码从ACAccountStore获取帐户: @H_404_2@- (void) facebookLoginOnSuccess: (void (^)(void)) successBlock onError:(void(^)(NSError *error))errorBlock{ self.facebookPermissions = @[ @"offline_access",@"publish_stream",@"user_birthday",@"user_location",@"email" ]; NSDictionary *options = @{ @"ACFacebookAppIDKey": [[NSBundle mainBundle] objectForInfoDictionaryKey:@"FacebookAppID"],@"ACFacebookAppVersionKey": @"1.0",@"ACFacebookPermissionsKey": self.facebookPermissions,@"ACFacebookPermissionGroupKey": @"write" }; [self accountLoginFor:ACAccountTypeIdentifierFacebook withOptions:options OnSuccess:successBlock onError:errorBlock]; } - (void) accountLoginFor: (NSString *) accountTypeID withOptions: (NSDictionary *) options OnSuccess: (void (^)(void)) successBlock onError:(void(^)(NSError *error))errorBlock{ ACAccountStore *accountStore = [[ACAccountStore alloc] init]; ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:accountTypeID]; [accountStore requestAccessToAccountsWithType:accountType options:options completion:^(BOOL granted,NSError *error){ if (granted){ NSArray *accountsArray = [accountStore accountsWithAccountType:accountType]; NSLog(@"%@",accountsArray); } else { NSLog(@"Error accessing account: %@",[error localizedDescription]); } }]; }

但是我收到这个错误

@H_404_2@Error Domain=com.apple.accounts Code=6 "The operation couldn't be completed. (com.apple.accounts error 6.)"

而且我找不到任何有关的东西,只是这个question.任何想法可能是错的?

更新

我在Apple Developer Docs上发现了这一点.

Accounts Framework

When requesting access to Facebook accounts,the only key required in your options dictionary is ACFacebookAppIdKey. ACFacebookPermissionGroupKey and ACFacebookAppVersionKey are now obsolete.

If you request a write permission under ACFacebookPermissionsKey,such as publish_stream,you must provide a value for ACFacebookAudienceKey,which can be one of ACFacebookAudienceEveryone,ACFacebookAudienceFriends,or ACFacebookAudienceOnlyMe.

所以我改变了我的选择:

@H_404_2@NSDictionary *options = @{ @"ACFacebookAppIDKey": [[NSBundle mainBundle] objectForInfoDictionaryKey:@"FacebookAppID"],@"ACFacebookAudienceKey": ACFacebookAudienceFriends };

但我收到同样的错误.

解决方法

好的,所以如果你没有在iOS 6中设置一个帐户,它将抛出错误代码6.如果用户只是拒绝许可而不是抛出错误代码7.如果我建议你请求用户首先设置她的帐户设置. @H_404_2@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."]; }); } }];
原文链接:https://www.f2er.com/iOS/330221.html

猜你在找的iOS相关文章