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

相关文章

当我们远离最新的 iOS 16 更新版本时,我们听到了困扰 Apple...
欧版/美版 特别说一下,美版选错了 可能会永久丧失4G,不过只...
一般在接外包的时候, 通常第三方需要安装你的app进行测...
前言为了让更多的人永远记住12月13日,各大厂都在这一天将应...