Iphone twitter.framework问题
我正在尝试在iOS 5上使用twitter实现单点登录,除了在settings.app中没有帐户时,应用程序会陷入无限循环,控制台上会显示此消息“twitter会话中断,重新启动。” 应用程序冻结在这行代码上Iphone twitter.framework问题,iphone,objective-c,twitter,ios5.1,Iphone,Objective C,Twitter,Ios5.1,我正在尝试在iOS 5上使用twitter实现单点登录,除了在settings.app中没有帐户时,应用程序会陷入无限循环,控制台上会显示此消息“twitter会话中断,重新启动。” 应用程序冻结在这行代码上 if ([TWTweetComposeViewController canSendTweet]) 非常感谢您的帮助 ///EDIT//// 这是我的密码 if([TWTweetComposeViewController canSendTweet]) { ACAccountStore*ac
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;
}
}];
}
}
}];
}
使用此代码检查Twitter帐户是否存在:-
if ([TWRequest class])
{
ACAccountStore *as = [[ACAccountStore alloc] init];
ACAccountType *accountType = [as accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
NSArray *twitterAccounts = [as accountsWithAccountType:accountType];
if (!twitterAccounts.count)
{
NSLog(@"No Twitter Account configured");
}
}
希望它能对您有所帮助!非常感谢,但我以前也尝试过。当我使用accounts中的类时,它会卡住。framework…在您的代码中,应用程序在ACAccountStore*上冻结为=[[ACAccountStore alloc]init];您是在模拟器还是在设备上测试它?我在设备和模拟器上都遇到了相同的问题。我添加了我的代码作为问题的编辑