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 controller. However, I get the following error when using the UIAlert:
wait_fences: failed to receive reply: 10004003
I debugged it, and googled around. I am not using a textarea or keyboard input, so I don't have to resign a first responder. However, I still cannot figure out why I would be getting this error. It only appears when I add the UIAlert.
MainController.m
- (void)viewDidLoad {
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];
[super viewDidLoad];
}
The header file is constructed like this:
@interface MainController : UIViewController
<CLLocationManagerDelegate,
MKReverseGeocoderDelegate, UIAlertViewDelegate>
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 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];
}
Always call [super viewDidLoad];
before you do anything else. That is also explaining why the delay works.
Hope I'm right. :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With