问题
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