当我用iOS 6.0运行下面的代码时,它工作正常
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运行这段代码时,它崩溃了,输出如下:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException',
reason: '-[ACAccountStore requestAccessToAccountsWithType:options:completion:]:
unrecognized selector sent to instance 0x68a57c0'不知道这个奇怪的崩溃日志..
请告诉我,如何摆脱这个..
发布于 2013-03-06 20:44:31
使用下面的方法:
[account requestAccessToAccountsWithType:accountType withCompletionHandler:^(BOOL granted, NSError *error)
{
if (granted) {
//Your code
}
}
}];发布于 2013-04-17 16:32:15
尝试对此进行更新:
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
}发布于 2013-09-06 00:51:03
这有点晚了,但是你得到这个错误的原因是requestAccessToAccountsWithType:options:completion:是iOS 6中的新特性。
在iOS 5和更早版本中,请改用requestAccessToAccountsWithType:withCompletionHandler方法(在iOS 6中不建议使用此方法)
https://stackoverflow.com/questions/15244861
复制相似问题