gpt4 book ai didi

ios - ACAccountStore 错误 6 (ACErrorAccountNotFound) 和 8

转载 作者:技术小花猫 更新时间:2023-10-29 10:55:18 25 4
gpt4 key购买 nike

我正在尝试使用以下代码从 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.)"

而且我找不到任何相关的东西,只有这个 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.

所以我将选项更改为:

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

但我遇到了同样的错误。

最佳答案

好的,如果您还没有在 iOS 6 的“设置”中设置帐户,它会抛出错误代码 6。如果用户简单地拒绝权限,那么它会抛出错误代码 7。在情况 6 中,我建议您让用户先在“设置”中设置她的帐户。

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."];

});
}
}];

关于ios - ACAccountStore 错误 6 (ACErrorAccountNotFound) 和 8,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12630066/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com