我正在使用以下代码在 iOS 6 中使用 SLRequest 和 ACAccounts 发布到 Twitter。问题是当有多个帐户时,我无法控制授予哪个帐户访问权限。让用户选择他们想要发布的帐户的建议?
-(void)twitteraccess {
ACAccountStore *account = [[ACAccountStore alloc] init];
ACAccountType *accountType = [account accountTypeWithAccountTypeIdentifier:
ACAccountTypeIdentifierTwitter];
[account requestAccessToAccountsWithType:accountType options:nil
completion:^(BOOL granted, NSError *error)
{
if (granted == YES)
{
NSArray *arrayOfAccounts = [account
accountsWithAccountType:accountType];
if ([arrayOfAccounts count] > 0)
{
ACAccount *twitterAccount = [arrayOfAccounts lastObject];
NSDictionary *message = @{@"status": @"Message"};
NSURL *requestURL = [NSURL
URLWithString:@"http://api.twitter.com/1/statuses/update.json"];
SLRequest *postRequest = [SLRequest
requestForServiceType:SLServiceTypeTwitter
requestMethod:SLRequestMethodPOST
URL:requestURL parameters:message];
postRequest.account = twitterAccount;
[postRequest performRequestWithHandler:^(NSData *responseData,
NSHTTPURLResponse *urlResponse, NSError *error)
{
NSLog(@"Twitter HTTP response: %i", [urlResponse
statusCode]);
}];
}
}
else {
if(error.code == 6){
[self performSelectorOnMainThread:@selector(alertmessagetwitter)
withObject:nil
waitUntilDone:YES]; }
}
}];
}