1

I am getting this cryptic message: wait_fences: failed to receive reply: 10004003 I have googled and people think it has something to do with not properly dismissing a UITextField or Alert. I have one textfield in my app and I assure you I release it properly using resignFirstResponder, etc... I get this message when I am opening a MPMusicPickerController from a subview, does that make any difference. I really need to get this fixed because it is messing up my whole app!

Thanks, Brad

Edit1:

    - (IBAction)openMediaPicker:(id)sender {
    [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationFade];
    MPMediaPickerController *mediaPicker = [[MPMediaPickerController alloc] initWithMediaTypes:MPMediaTypeAny];
    mediaPicker.delegate = self;
    mediaPicker.allowsPickingMultipleItems = YES;
    mediaPicker.prompt = @"Select songs to play";
    [self presentModalViewController:mediaPicker animated:YES];
    [mediaPicker release];
} 

// Media picker delegate methods
- (void)mediaPicker: (MPMediaPickerController *)mediaPicker didPickMediaItems:(MPMediaItemCollection *)mediaItemCollection {

    AppAppDelegate *appDelegate = (AppAppDelegate *)[[UIApplication sharedApplication] delegate];
    [appDelegate.tr2 stop];
    [playstopButton setHidden:NO];
    [playstopButton setImage:[UIImage imageNamed:@"Stop-Music-Button.png"] forState:UIControlStateNormal];
    // We need to dismiss the picker
    [self dismissModalViewControllerAnimated:YES];
    [[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationFade];

    // Assign the selected item(s) to the music player and start playback.
    [self.musicPlayer stop];
    [self.musicPlayer setQueueWithItemCollection:mediaItemCollection];
    [self.musicPlayer play];

}

- (void)mediaPickerDidCancel:(MPMediaPickerController *)mediaPicker {
    // User did not select anything
    // We need to dismiss the picker
    [self dismissModalViewControllerAnimated:YES];
    [[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationFade];
}
Peter Hosey
  • 95,783
  • 15
  • 211
  • 370
SimplyKiwi
  • 12,376
  • 22
  • 105
  • 191

2 Answers2

4

Generally:

  1. You should not do any animations in viewWillAppear only in viewDidAppear. Only prepare your data, outlets etc. in viewWillAppear.

  2. Also a very common case where wait_fences might arise is when you have an animated dialog (Like your MPMediaPickerController) that causes another animated view to appear (Like a custom modal UIViewController) or the like, in which case you need to "postpone" the presentation of the second viewcontroller like this:

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

Also check out this answer https://stackoverflow.com/7194182.

Edit

A good way to "debug" conflicting animations is to simply set the animation to NO so in your code instead of

    [self presentModalViewController:mediaPicker animated:YES];
    [self dismissModalViewControllerAnimated:YES];

Simply do:

    [self presentModalViewController:mediaPicker animated:NO];
    [self dismissModalViewControllerAnimated:NO];

and check if the wait_fences error goes away and the correct behaviour (but without animation) is achieved. If this is the case you need some of the performSelector:withObject:afterDelay:-magic.

Edit: Please note that you can do the following in iOS 5.0:

[self dismissViewControllerAnimated:YES completion:^{
    [self presentViewController:anotherViewController animated:YES completion:NULL]
}

That means that first, the currently presented View Controller (e.g. a ModalViewController) is dismissed and when the animation is finished you can invoke another block. In this case show another UIViewController

Community
  • 1
  • 1
Besi
  • 22,579
  • 24
  • 131
  • 223
  • What exactly is wait_fences? Does it make my app slower, less efficient? – SimplyKiwi Jan 09 '12 at 23:26
  • I don't know what wait_fences exactly means, but I think it's thrown when animations and UI-drawing related errors or "collisions" occur. I don't think that it makes your App slower, but it suggests that there is a problem in your code, which you should obviously try to resolve. – Besi Jan 12 '12 at 12:57
  • I just wanted to let you know that you are my hero, been trying to fix this issue for several days and the performSelector:withObject:afterDelay: method did the trick. – robhasacamera Aug 22 '12 at 17:43
0

I also noticed that replacing clickedButtonAtIndex: with didDismissWithButtonIndex: when using UIActionSheet or UIAlertView seems to make the error message go away.

Dasha Salo
  • 5,159
  • 5
  • 26
  • 28