1

OKユーザーがAddressBook パーミッションを押すたびに、UIAlertViewこれらのコマンドの実行に遅延が生じることを除けば、すべてうまくいきますNSLog

同じコードは、カレンダーのアクセス許可で即座に機能します。

誰かがここで私を助けてくれますか? ありがとうございました。

遅延(5秒)後に実行されているコード

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

完全な機能

ABAddressBookRef addressBookRef = ABAddressBookCreateWithOptions(NULL, NULL);

if (ABAddressBookGetAuthorizationStatus() == kABAuthorizationStatusNotDetermined) {

ABAddressBookRequestAccessWithCompletion(addressBookRef, ^(bool 付与, CFErrorRef エラー) {

もし(エラー)

        {
            // display error message here
        }

そうでなければ (!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];
        }



    });
}
4

1 に答える 1

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];
});
于 2013-10-26T09:58:16.730 に答える