wait_fences: failed to receive reply: 10004003 error - UIAlert WITHOUT UITextField present

风格不统一 提交于 2019-11-27 08:45:41
MacMark

The reason for this wait_fences: failed to receive reply: can also be that you try to show an alert while not being on the mainThread (which is the GUI thread).

Dispatching to the GUI thread helps:

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

I solved this problem by adding a slight delay to the UIAlert: The below is within my ViewDidLoad method (it also works fine within ViewDidAppear):

[self performSelector:@selector(testAlert) withObject:nil afterDelay:0.1];

for some reason that delay did the trick. I then called another method (I will rename it of course..):

- (void) testAlert
{
    UIAlertView *mainAlert = [[UIAlertView alloc] initWithTitle:@"Location" message:@"Do you wish to use your current location?" delegate:self cancelButtonTitle:nil otherButtonTitles:@"No Thanks", @"Sure!", nil];

    [mainAlert show];
    [mainAlert release];
}
Glünggi

Always call [super viewDidLoad]; before you do anything else. That is also explaining why the delay works.

Hope I'm right. :)

Try showing the UIAlert in -viewDidAppear:(BOOL)animated. -viewDidLoad is called when your view is loaded, but before it is on screen.

I had a similar problem. I was adding an observer in the ViewDidLoad for a reachability notification, which was getting posted before the ViewDidAppear was finished.

So the ViewController was trying to display one UIAlertView before its own View was drawn completely.

I moved the adding of Observers to the ViewDidAppear, and started the startNotifier of reachability in the ViewDidAppear. Also the call to [super viewDidAppear] was missed from the code. Both these issues corrected, the app became working fine again.

If you get this wait_fences: failed to receive reply: 10004003 error once, you may not be able to present any modal ViewControllers in the app further. This was the problem I had in my app. Sometimes when trying to present one modal ViewController, the app would go into an infinite loop.

As Alan said, always remember to "Try showing the UIAlert in -viewDidAppear:(BOOL)animated. -viewDidLoad is called when your view is loaded, but before it is on screen."

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!