在 Twitter 完成块中推送 UIViewController 的大量时间 [英] Substantial time to push UIViewController in Twitter completion block

查看:16
本文介绍了在 Twitter 完成块中推送 UIViewController 的大量时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

运行此代码时...

-(IBAction)loginWithTwitter:(id)sender {
NSLog(@"Logging in with twitter");
ACAccountStore *accountStore = [[ACAccountStore alloc]init];
ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];

[accountStore requestAccessToAccountsWithType:accountType options:nil completion:^(BOOL granted, NSError *error) {
    if (error) {
        [self showError:error];
        return;
    }

    if (granted) {
        NSArray *accountsArray = [accountStore accountsWithAccountType:accountType];

        if ([accountsArray count] > 1) {
            NSLog(@"Multiple twitter accounts");
        }

        ACAccount *twitterAccount = [accountsArray objectAtIndex:0];
        NSLog(@"%@", twitterAccount);

        [self pushMainController];
    }
}];
}

在实际调用 pushMainController 之前有 5-10 秒的延迟,即使帐户信息几乎立即被记录(在预授权之后).但是,如果我在块之后移动 pushMainController 调用,它会立即发生,唯一的问题是用户不一定在那时登录.我知道由于网络连接等变量,块可能需要一秒钟才能做出响应,但有人可以帮助我理解这一点吗?

There is a 5-10 second delay before the pushMainControlleris actually called, even though the account information is logged almost immediately (after pre-authorization). If I move the pushMainController call after the block however, it happens immediately, the only problem being that a user isn't necessarily logged in at that point. I understand that it can take a second for a block to have a response due to variables such as network connectivity, but can someone help me understand this?

推荐答案

未在主队列上完成完成块.您需要确保您的 UI 代码在主线程上完成:

The completion block is not being done on the main queue. You need to ensure your UI code gets done on the main thread:

[accountStore requestAccessToAccountsWithType:accountType options:nil completion:^(BOOL granted, NSError *error) {
    if (error) {
        [self showError:error];
        return;
    }

    if (granted) {
        NSArray *accountsArray = [accountStore accountsWithAccountType:accountType];

        if ([accountsArray count] > 1) {
            NSLog(@"Multiple twitter accounts");
        }

        ACAccount *twitterAccount = [accountsArray objectAtIndex:0];
        NSLog(@"%@", twitterAccount);

        dispatch_async(dispatch_get_main_queue(), ^{
            [self pushMainController];
        });
    }
}];

您可能还需要包装 showError 调用.

You may have to wrap the showError call as well.

这篇关于在 Twitter 完成块中推送 UIViewController 的大量时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆