Rui*_*res 7 ios ios6 acaccount
我使用以下代码(在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...
}
}];
Run Code Online (Sandbox Code Playgroud)
我还在NSDictionary我的.plist文件中添加了:

所以,我的问题是我收到以下异常:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Access options are required for this account type.'
Run Code Online (Sandbox Code Playgroud)
我试过这个ACAccountTypeIdentifierTwitter和ACAccountTypeIdentifierSinaWeibo.我没有收到任何例外,尽管他们总是回来granted == NO
Rui*_*res 17
好吧,WWDC 2012显示了一件事,但文档显示了另一个......他们正在使用的方法现已弃用:
– requestAccessToAccountsWithType:withCompletionHandler: Deprecated in iOS 6.0
Run Code Online (Sandbox Code Playgroud)
你应该做什么:
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...
}
}];
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9517 次 |
| 最近记录: |