我正在尝试在 iOS 5 上使用 twitter 实现单点登录,一切正常,除非 settings.app 中没有帐户,应用程序陷入似乎无限循环的状态,并且此消息出现在控制台上“twitterd会话中断,正在重新启动。”
应用程序冻结在这行代码上
if ([TWTweetComposeViewController canSendTweet])
非常感谢任何帮助。
//////EDIT//////// 这是我的代码 if ([TWTweetComposeViewController canSendTweet]) { ACAccountStore *accountStore = [[ACAccountStore alloc] init];
// Create an account type that ensures Twitter accounts are retrieved.
ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
// Request access from the user to use their Twitter accounts.
[accountStore requestAccessToAccountsWithType:accountType withCompletionHandler:^(BOOL granted, NSError *error) {
if(granted) {
// Get the list of Twitter accounts.
NSArray *accountsArray = [accountStore accountsWithAccountType:accountType];
// For the sake of brevity, we'll assume there is only one Twitter account present.
// You would ideally ask the user which account they want to tweet from, if there is more than one Twitter account present.
if ([accountsArray count] > 0)
{
// Grab the initial Twitter account to tweet from.
ACAccount *twitterAccount = [accountsArray objectAtIndex:0];
NSURL *url = [NSURL URLWithString:@"http://api.twitter.com/1/account/verify_credentials.json"];
TWRequest *req = [[TWRequest alloc] initWithURL:url
parameters:nil
requestMethod:TWRequestMethodGET];
// Important: attach the user's Twitter ACAccount object to the request
req.account = twitterAccount;
[req performRequestWithHandler:^(NSData *responseData,
NSHTTPURLResponse *urlResponse,
NSError *error) {
// If there was an error making the request, display a message to the user
if(error != nil) {
}
// Parse the JSON response
NSError *jsonError = nil;
id resp = [NSJSONSerialization JSONObjectWithData:responseData
options:0
error:&jsonError];
// If there was an error decoding the JSON, display a message to the user
if(jsonError != nil) {
return;
}
}];
}
}
}];
}