2013-05-09 76 views
4

據我瞭解,當我調用[ACAccountStore requestAccessToAccountsWithType:options:completion]時,用戶應該看到一個UIAlert,詢問他們是否授予我的應用程序權限。iOS requestAccessToAccountsWithType不顯示權限提示/ NSAlert

當我運行這段代碼,從來就沒有提示和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設置有關...

+0

的輸出是什麼數? – 2013-05-09 18:59:21

+0

已更新的原帖 – Chris 2013-05-09 19:01:50

+0

可能重複[獲取「錯誤代碼8」時調用\ [ACAccountStore requestAccessToAccountsWithType \] - iOS的Facebook](http://stackoverflow.com/questions/16425325/getting-error-code-8-when-主叫acaccountstore-requestaccesstoaccountswitht) – WrightsCS 2013-09-20 19:44:22

回答

3

你已經倒在你的選擇字典對象和密鑰:

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

Yo你實際上錯過了一個關鍵:ACFacebookAudienceKey。 你可以改變它像:

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

順便說一句,當你使用Twitter,選項必須nil