首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >推特与ACAccountStore (iOS 5)的集成问题

推特与ACAccountStore (iOS 5)的集成问题
EN

Stack Overflow用户
提问于 2013-03-06 18:32:46
回答 4查看 2.9K关注 0票数 4

当我用iOS 6.0运行下面的代码时,它工作正常

代码语言:javascript
复制
ACAccountStore *account = [[ACAccountStore alloc] init];
ACAccountType *accountType = [account accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];

[account requestAccessToAccountsWithType:accountType options:nil
                                  completion:^(BOOL granted, NSError *error)
     {
         dispatch_async(dispatch_get_main_queue(), ^{

             if (granted) 
             {
                 //MY CODE
             }
         });

     }];

当我用iOS 5.0或5.1运行这段代码时,它崩溃了,输出如下:

代码语言:javascript
复制
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', 
reason: '-[ACAccountStore requestAccessToAccountsWithType:options:completion:]: 
unrecognized selector sent to instance 0x68a57c0'

不知道这个奇怪的崩溃日志..

请告诉我,如何摆脱这个..

EN

回答 4

Stack Overflow用户

发布于 2013-03-06 20:44:31

使用下面的方法:

代码语言:javascript
复制
[account requestAccessToAccountsWithType:accountType withCompletionHandler:^(BOOL granted, NSError *error)
 {

   if (granted) {

            //Your code
            }
        }
   }];
票数 5
EN

Stack Overflow用户

发布于 2013-04-17 16:32:15

尝试对此进行更新:

代码语言:javascript
复制
ACAccountStore *account = [[ACAccountStore alloc] init];
ACAccountType *accountType = [account accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];

// iOS 6
if ( [account respondsToSelector:@selector(requestAccessToAccountsWithType: options: completion:)] )
{
[account requestAccessToAccountsWithType:accountType options:nil
                                  completion:^(BOOL granted, NSError *error)
     {
         dispatch_async(dispatch_get_main_queue(), ^{

             if (granted) 
             {
                 //MY CODE
             }
         });

     }];
}

// iOS 5
else if ( [account respondsToSelector:@selector(requestAccessToAccountsWithType: withCompletionHandler:)] )
{
[account requestAccessToAccountsWithType:accountType
                                  withCompletionHandler:^(BOOL granted, NSError *error)
     {
         dispatch_async(dispatch_get_main_queue(), ^{

             if (granted) 
             {
                 //MY CODE
             }
         });

     }];
}
else
{
// iOS 4 or less
}
票数 1
EN

Stack Overflow用户

发布于 2013-09-06 00:51:03

这有点晚了,但是你得到这个错误的原因是requestAccessToAccountsWithType:options:completion:是iOS 6中的新特性。

在iOS 5和更早版本中,请改用requestAccessToAccountsWithType:withCompletionHandler方法(在iOS 6中不建议使用此方法)

请参阅文档:https://developer.apple.com/library/ios/documentation/Accounts/Reference/ACAccountStoreClassRef/Reference/Reference.html#//apple_ref/doc/uid/TP40011021-CH1-SW12

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15244861

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档