【问题标题】:Code Execution Delay After Addressbook Permit地址簿许可后的代码执行延迟
【发布时间】:2013-10-26 08:50:43
【问题描述】:

每当用户在地址簿权限UIAlertView 上按下OK 时,一切正常,除了执行这些命令的延迟,奇怪的是,这些命令需要大约 5 秒才能执行,即使打印了NSLog瞬间。

相同的代码在日历权限中立即生效。

有人可以帮我吗?谢谢你。

延迟(5秒)后正在执行的代码

   NSLog(@"Granted!");
 _1234.backgroundColor = [UIColor lightGrayColor];
 [_12345 setHidden:NO];
 [ _qwerty setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
 [_qwerty1 setHidden:YES];

功能齐全

ABAAddressBookRef addressBookRef = ABAddressBookCreateWithOptions(NULL, NULL);

如果 (ABAAddressBookGetAuthorizationStatus() == kABAuthorizationStatusNotDetermined) {

ABAddressBookRequestAccessWithCompletion(addressBookRef, ^(bool 授予,CFErrorRef 错误){

如果(错误)

        {
            // display error message here
        }

else if (!granted)

        {
            // display access denied error message here

        }
        else
        {
            NSLog(@"Granted!"); //this gets printed instantly

            _qwerty.userInteractionEnabled = NO;

            _1234.backgroundColor = [UIColor lightGrayColor];
            [_12345 setHidden:NO];
            [ _qwerty setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
            [_qwerty1 setHidden:YES];

            [self qwerty4];
        }



    });
}

【问题讨论】:

    标签: ios objective-c ios7 abaddressbook


    【解决方案1】:

    你的延迟可能是因为完成块没有在主线程中执行,所有UI操作都必须在主线程中执行,像这样在主线程中调度你的UI代码:

    dispatch_async(dispatch_get_main_queue(), ^{
    
        NSLog(@"Granted!"); //this gets printed instantly
    
        _qwerty.userInteractionEnabled = NO;
    
        _1234.backgroundColor = [UIColor lightGrayColor];
        [_12345 setHidden:NO];
        [ _qwerty setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
        [_qwerty1 setHidden:YES];
    
        [self qwerty4];
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-12-11
      • 1970-01-01
      • 2013-10-02
      • 2011-10-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多