iOS的requestAccessToAccountsWithType没有显示权限提示/ NSAle

2019-09-02 10:02发布

这是我的理解是,当我调用[ACAccountStore requestAccessToAccountsWithType:options:completion] ,用户应该看到,询问他们是否授予权限,我的应用程序的UIAlert。

当我运行这段代码,从来就没有提示和granted变量始终是“假”

-(void)myfunction { 
if (!_accountStore) _accountStore = [[ACAccountStore alloc] init];

    ACAccountType *fbActType = [_accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];


    NSDictionary *options = [[NSDictionary alloc] initWithObjectsAndKeys:
                             (NSString *)ACFacebookAppIdKey, @"##########",  
                             (NSString *)ACFacebookPermissionsKey, [NSArray arrayWithObject:@"email"],  
                             nil];


    [_accountStore requestAccessToAccountsWithType:fbActType options:options completion:^(BOOL granted, NSError *error) {
                                                NSLog(@"Home.m - getFBDetails - Check 2");
                                                if (granted == YES) {
                                                    NSLog(@"Success");
                                                    NSArray *accounts = [_accountStore accountsWithAccountType:fbActType];
                                                    _facebookAccount = [accounts lastObject];                                                    
                                                    [self me];
                                               } else {
                                                    NSLog(@"ERR: %@ ",error);
                                                    // Fail gracefully...
                                              }
            }
     ];

}

而我得到的错误: ERR: Error Domain=com.apple.accounts Code=8 "The operation couldn't be completed. (com.apple.accounts error 8.)"

更新:我做了一些测试,如果我使用运行ACAccountTypeIdentifierTwitter ,我得到的提示连接到我的Twitter账户,所以我假定这是一些与我的Facebook设置...

Answer 1:

你已经倒在你的选择字典对象和密钥:

NSDictionary *options = [[NSDictionary alloc] initWithObjectsAndKeys:
                         @"##########",  ACFacebookAppIdKey,
                         [NSArray arrayWithObject:@"email"], ACFacebookPermissionsKey,
                         nil];


Answer 2:

你实际上是缺少一个关键:ACFacebookAudienceKey。 你可以这样改变它:

NSDictionary *options = [[NSDictionary alloc] initWithObjectsAndKeys:
                                 (NSString *)ACFacebookAppIdKey, @"##########",  
                                 (NSString *)ACFacebookPermissionsKey, [NSArray arrayWithObject:@"email"],
                                 (NSString *)ACFacebookAudienceKey, ACFacebookAudienceEveryone,
                                 nil];

顺便说一句,当你使用Twitter,选项必须是nil



文章来源: iOS requestAccessToAccountsWithType is Not Showing Permission Prompt / NSAlert