Ios 行动警报弹出前明显滞后

Ios 行动警报弹出前明显滞后,ios,Ios,执行以下操作时,如果NSLog和显示的警报之间未授予访问权限,则会出现明显的延迟。即使没有其他方法正在运行 [_accountStore requestAccessToAccountsWithType:_accountType options:nil completion:^(BOOL granted, NSError *error) { if (granted ==YES){ NSLog(@"Granted"); }else{ NSLog(@

执行以下操作时,如果NSLog和显示的警报之间未授予访问权限,则会出现明显的延迟。即使没有其他方法正在运行

[_accountStore requestAccessToAccountsWithType:_accountType options:nil completion:^(BOOL granted, NSError *error) {
    if (granted ==YES){

        NSLog(@"Granted");

    }else{
        NSLog(@"NO TWITTER ACCESS");
        UIAlertView *alert =[[UIAlertView alloc ] initWithTitle:@"Need Twitter Access"
                                                        message:@"Please enable twitter access." 
                                                       delegate:self
                                              cancelButtonTitle:@"OK"
                                              otherButtonTitles: nil];
        [alert show];
    }
}];

多亏了@rmaddy。在主线程上显示警报解决了延迟问题

dispatch_async(dispatch_get_main_queue(),^ {
            [alert show];
        } );

你需要在主线程上进行UI更新,而不是在后台线程上。你怎么知道它在后台线程上?我假设是这样,因为它是从异步完成块调用的,而异步完成块通常在一些非主线程上调用。您描述的症状是在后台线程上执行UI更新时的典型症状。谢谢,这确实是问题所在。