iPad模拟器无法在iPhone应用程序中使用UIImagePickerController

Way*_*Liu 9 xcode objective-c uiimagepickercontroller

我正在创建一个iPhone应用程序,它使用UIImagePickerController让用户从照片库中选择一个图像.

选择器允许我成功地从照片库中获取图像:

  • iPhone sumulator
  • 真正的iPhone运行5.0.1
  • 真正的iPad运行5.0.1
  • 真正的iPad运行5.1
  • iPad模拟器v4.3

但是如果我测试这个应用程序,那么选择器无法获得图像:

  • iPad模拟器v5.0
  • iPad模拟器v5.1

在这两个测试环境中,图像选择器成功出现.当我点击我需要的图像时,它不会通过方法" - (void)imagePickerController:(UIImagePickerController*)picker didFinishPickingMediaWithInfo:(NSDictionary*)info " 从" [info objectForKey:UIImagePickerControllerOriginalImage] " 给我任何东西.

"info"字典就像这样:

{
    UIImagePickerControllerMediaType = "public.image";
    UIImagePickerControllerReferenceURL = "assets-library://asset/asset.PNG?id=7632C58F-AF74-4EEB-AF17-891E35949CBA&ext=PNG";
}
Run Code Online (Sandbox Code Playgroud)

在以前的5个测试环境中,"info"就像这样:

{
    UIImagePickerControllerMediaType = "public.image";
    UIImagePickerControllerOriginalImage = "<UIImage: 0x6bb7810>";
    UIImagePickerControllerReferenceURL = "assets-library://asset/asset.PNG?id=7632C58F-AF74-4EEB-AF17-891E35949CBA&ext=PNG";
}
Run Code Online (Sandbox Code Playgroud)

您可以看到缺少UIImagePickerControllerOriginalImage.我不确定这只是我吗?

注意:我在iOS 5 SDK中使用Xcode 4.3.2

注2:我没有使用AssetsLibrary框架来获取图像.

注释3(2012年8月2日添加):我已经安装了Mountain Lion升级到Xcode 4.4.同样的问题仍然存在.但是现在如果我在iPad模拟器v5.0中运行它会出现一条新的错误消息(如果我在iPad模拟器v5.1上运行它,则不会显示错误消息).错误消息显示:找不到命名服务'com.apple.PersistentURLTranslator.Gatekeeper'.assetsd已关闭或配置错误.事情不会像你期望的那样发挥作用.

注释4(2012年11月25日添加):使用Xcode 4.5.2,iPad模拟器5.0,5.1和6.0中仍存在此问题

注释5(2012年3月6日添加):使用Xcode 4.6,这个问题仍然存在于iPad模拟器的所有版本中.

fre*_*cer 0

在实际设备中尝试一下

     - (IBAction)BrowseImage:(id)sender {

  if ([UIImagePickerController isSourceTypeAvailable:
     UIImagePickerControllerSourceTypeSavedPhotosAlbum])
{
    UIImagePickerController *imagePicker =
    [[UIImagePickerController alloc] init];
    imagePicker.delegate = self;
    imagePicker.sourceType = 
    UIImagePickerControllerSourceTypePhotoLibrary;
    imagePicker.mediaTypes = [NSArray arrayWithObjects:
                              (NSString *) kUTTypeImage,
                              nil];
    imagePicker.allowsEditing = NO;
    [self presentModalViewController:imagePicker animated:YES];
    //newMedia = NO;
}   


-(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
  {

[self dismissModalViewControllerAnimated:YES];


 }
Run Code Online (Sandbox Code Playgroud)