iOS requestAccessToAccountsWithType is Not Showing Permission Prompt / NSAlert

时光怂恿深爱的人放手 提交于 2019-12-01 21:34:10

问题


It is my understanding that when I invoke [ACAccountStore requestAccessToAccountsWithType:options:completion], the user is supposed to see an UIAlert that asks them if they grant permission to my app.

When I run this code, there is never a prompt and the granted variable is always "false"

-(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...
                                              }
            }
     ];

}

And I get the Error: ERR: Error Domain=com.apple.accounts Code=8 "The operation couldn’t be completed. (com.apple.accounts error 8.)"

Update: I did some testing and if I run with using ACAccountTypeIdentifierTwitter, I get the prompt to connect to my Twitter accounts, so I am supposing it is something with my Facebook settings ...


回答1:


You have inverted objects and keys in your options dictionary :

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



回答2:


You are actually missing a key: ACFacebookAudienceKey. You can change it like that:

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

By the way, when you are using Twitter, the options must be nil.



来源:https://stackoverflow.com/questions/16469077/ios-requestaccesstoaccountswithtype-is-not-showing-permission-prompt-nsalert

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!