开发者

UIImagePickerController intermittently stops responding after tapping "Use" button

开发者 https://www.devze.com 2023-02-18 00:53 出处:网络
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.

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开发者_Go百科 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];


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.


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.


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.

0

精彩评论

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