我正在尝试使用以下代码从 ACAccountStore 获取帐户:
- (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]);
}
}];
}
但我收到了这个错误:
Error Domain=com.apple.accounts Code=6 "The operation couldn't be completed. (com.apple.accounts error 6.)"
而且我找不到任何相关的东西,只是这个问题。有什么想法可能是错的吗?
更新
我在 Apple Developer Docs 上找到了这个。
账户框架
当请求访问 Facebook 帐户时,您的选项字典中唯一需要的键是 ACFacebookAppIdKey。ACFacebookPermissionGroupKey 和 ACFacebookAppVersionKey 现已过时。
如果您在 ACFacebookPermissionsKey 下请求写入权限,例如 publish_stream,则必须为 ACFacebookAudienceKey 提供一个值,该值可以是ACFacebookAudienceEveryone、ACFacebookAudienceFriends或ACFacebookAudienceOnlyMe 之一。
所以我改变了我的选择:
NSDictionary *options = @{
@"ACFacebookAppIDKey": [[NSBundle mainBundle] objectForInfoDictionaryKey:@"FacebookAppID"],
@"ACFacebookPermissionsKey": self.facebookPermissions,
@"ACFacebookAudienceKey": ACFacebookAudienceFriends
};
但我遇到了同样的错误。