微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

ios – ACAccountStore错误6(ACErrorAccountNotFound)和8

我试图使用以下代码从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"],@"ACFacebookAudienceKey": ACFacebookAudienceFriends
    };

但我收到同样的错误.

解决方法

好的,所以如果你没有在iOS 6中设置一个帐户,它将抛出错误代码6.如果用户只是拒绝许可而不是抛出错误代码7.如果我建议你请求用户首先设置她的帐户设置.
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.jb51.cc/iOS/330221.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐