iOS requestAccessToAccountsWithType未显示权限提示/ NSAlert

时间:2013-05-09 18:56:11

标签: ios facebook acaccountstore

据我了解,当我调用[ACAccountStore requestAccessToAccountsWithType:options:completion]时,用户应该会看到一个UIAlert询问他们是否授予我的应用权限。

当我运行此代码时,从来没有提示,granted变量始终为“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...
                                              }
            }
     ];

}

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

更新:我做了一些测试,如果我使用ACAccountTypeIdentifierTwitter运行,我会收到连接到我的Twitter帐户的提示,所以我认为这是我的Facebook设置...

2 个答案:

答案 0 :(得分:3)

您的选项词典中有倒置的对象和键:

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

答案 1 :(得分:2)

您实际上错过了一个键: ACFacebookAudienceKey 。 你可以改变它:

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

顺便说一下,当您使用Twitter时,选项必须是nil