Ross
Ross

Reputation: 1934

UIImagePickerController intermittently stops responding after tapping "Use" button

I have an app that records video. The app is a mixture of cocos2d and UIKit though the part using the UIImagePickerController is all UIKit.

The Problem: After taking a video, when you tap the "Use" button, the button changes to selected state and then nothing happens. The "Retake" button is disabled. You can still Play/Pause the video but the view never dismisses and - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info is never called.

The problem happens on long and short (<5 second) videos. Causing memory warnings did not reproduce the issue. Changing audio sessions before launching the image picker did not reproduce the issue either.

I have been unable to cause the issue. It happens only occasionally. Any ideas?

Here is the code that presents the UIImagePickerController

  UIImagePickerController *tmpVC = [[UIImagePickerController alloc] init];
  tmpVC.delegate = self;
  tmpVC.allowsEditing = YES;
  // First get the right media types for the right source
  NSArray *types = nil;
  if (useCamera)
  {
    types = [UIImagePickerController availableMediaTypesForSourceType:UIImagePickerControllerSourceTypeCamera];
    tmpVC.sourceType = UIImagePickerControllerSourceTypeCamera;
  }
  else
  {
    types = [UIImagePickerController availableMediaTypesForSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
    tmpVC.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
  }

  // Then see if "movie" is in there
  for (NSString *mediaType in types)
  {
    if ([mediaType isEqualToString:(NSString*)kUTTypeMovie])
    {
      tmpVC.mediaTypes = [NSArray arrayWithObjects:(NSString*)kUTTypeImage,(NSString*)kUTTypeMovie,nil];
      tmpVC.videoQuality = UIImagePickerControllerQualityTypeHigh;
    }
  }

  // Present the configured controller
  [self presentModalViewController:tmpVC animated:YES];
  [tmpVC release];

Upvotes: 8

Views: 1109

Answers (3)

user79758
user79758

Reputation:

The cause of my problem was that in iOS 5,

[picker.parentViewController dismissModalViewControllerAnimated:YES]

no longer works - parentViewController is nil. Confusingly, this causes the picker view to be "finished" but not dismissed, and it just remains inactive.

Instead, you can use:

[picker.presentingViewController dismissModalViewControllerAnimated:YES]

But this doesn't work in iOS 4, as there is no presentingViewController message.

You can either write a category that automatically picks the right one, or keep a reference to the view controller that presented it manually. For example in my case the delegate was also the view controller which presented it, so I was able to do

[self dismissModalViewControllerAnimated:YES]

In my selector.

Upvotes: 1

Milk Tea
Milk Tea

Reputation: 141

I would look else where in your code, is it called in a if statement? Did you alloc and init the thing that calls the - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info. Those are just some little things I would look for, plus call a NSLog() where you see the call the function to know it has been called or there could be an error there.

Upvotes: 1

Mihai Fratu
Mihai Fratu

Reputation: 7663

Are you testing the app in the Simulator? Try testing it on a device and see if it does the same. I remember that I had a similar problem where I couldn't select a video with the picker in the Simulator because the application will just get "stuck" after I pressed the Use button.

Upvotes: 1

Related Questions