【问题标题】:twitter.framework problemstwitter.framework 问题
【发布时间】:2012-11-05 09:34:31
【问题描述】:

我正在尝试在 iOS 5 上使用 twitter 实现单点登录,一切正常,除非 settings.app 中没有帐户,应用程序陷入看似无限循环的状态,并且此消息出现在控制台 " twitterd 会话中断,正在重新启动。"

应用程序冻结在这行代码

if ([TWTweetComposeViewController canSendTweet])

非常感谢任何帮助。

//////编辑///////// 这是我的代码 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;
                }




            }];


        }
    }
}];
 }

【问题讨论】:

    标签: iphone objective-c twitter ios5.1


    【解决方案1】:

    使用此代码检查 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");
    
                }
                }
    

    希望对你有帮助!

    【讨论】:

    • 非常感谢,但我以前试过这个。每当我使用帐户中的课程时,它就会卡住。框架...在您的代码中,应用程序冻结在 ACAccountStore *as = [[ACAccountStore alloc] init];
    • 你是在模拟器还是设备上测试?
    • 我在设备和模拟器上都遇到了同样的问题。我将我的代码添加为问题的编辑
    猜你喜欢
    • 2012-06-22
    • 2012-06-23
    • 1970-01-01
    • 2012-02-19
    • 2013-12-04
    • 2012-01-28
    • 2013-09-17
    • 2023-03-19
    • 1970-01-01
    相关资源
    最近更新 更多