iOS6中的Facebook集成错误(Accounts.framework)

我使用以下代码(在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...
                                     }
                                 }];

我还在我的.plist文件添加了NSDictionary:

所以,我的问题是我收到以下异常:

*** Terminating app due to uncaught exception 'NSinvalidargumentexception',reason: 'Access options are required for this account type.'

我尝试过这个ACAccountTypeIdentifierTwitter和ACAccountTypeIdentifierSinaWeibo.我没有收到任何例外,虽然他们总是返回授予==否

解决方法

好吧,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...
                                     }
                                 }];

相关文章

UITabBarController 是 iOS 中用于管理和显示选项卡界面的一...
UITableView的重用机制避免了频繁创建和销毁单元格的开销,使...
Objective-C中,类的实例变量(instance variables)和属性(...
从内存管理的角度来看,block可以作为方法的传入参数是因为b...
WKWebView 是 iOS 开发中用于显示网页内容的组件,它是在 iO...
OC中常用的多线程编程技术: 1. NSThread NSThread是Objecti...