我使用以下代码(在WWDC 2012视频中显示):
self.accountStore = [[ACAccountStore alloc] init];
ACAccountType *facebookAccountType = [self.accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];
[self.accountStore requestAccessToAccountsWithType:facebookAccountType
withCompletionHandler:^(BOOL granted, NSError *e) {
if (granted)
{
NSArray *accounts = [self.accountStore
accountsWithAccountType:facebookAccountType];
self.facebookAccount = [accounts lastObject];
} else {
// Fail gracefully...
}
}];
我还将NSDictionary
添加到我的.plist
文件中:
所以,我的问题是我收到以下异常:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Access options are required for this account type.'
我尝试过这个ACAccountTypeIdentifierTwitter
和ACAccountTypeIdentifierSinaWeibo
。我没有收到任何例外,尽管他们总是返回granted == NO
答案 0 :(得分:17)
嗯,WWDC 2012显示了一件事,但documentation显示了另一个......他们正在使用的方法现已弃用:
– requestAccessToAccountsWithType:withCompletionHandler: Deprecated in iOS 6.0
你应该做什么:
ACAccountType *facebookAccountType = [self.accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];
NSDictionary *options = @{
@"ACFacebookAppIdKey" : @"123456789",
@"ACFacebookPermissionsKey" : @[@"publish_stream"],
@"ACFacebookAudienceKey" : ACFacebookAudienceEveryone}; // Needed only when write permissions are requested
[self.accountStore requestAccessToAccountsWithType:facebookAccountType options:options
completion:^(BOOL granted, NSError *error) {
if (granted)
{
NSArray *accounts = [self.accountStore
accountsWithAccountType:facebookAccountType];
self.facebookAccount = [accounts lastObject];
} else {
NSLog(@"%@",error);
// Fail gracefully...
}
}];
答案 1 :(得分:0)
Swift 3
table does not exist