开发者

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

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. :)


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."

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜