I am working on an app where a UIAlert pops up the first time the user begins using it to ask if they want to use their current location. This happens within the main contro
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];
});
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."
Always call [super viewDidLoad];
before you do anything else. That is also explaining why the delay works.
Hope I'm right. :)
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];
}
Try showing the UIAlert in -viewDidAppear:(BOOL)animated. -viewDidLoad is called when your view is loaded, but before it is on screen.