Image not returned by didFinishPickingMediaWithInfo:

左心房为你撑大大i 提交于 2019-12-09 22:11:19

问题


I'm basically trying to 'get' an image from the users photo library (or camera). The problem is, no image is returned when on iPad (Compatibility mode). Here is the code:

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {

    NSLog(@"info: %@", info);
}

iPhone and iPhone simulator log (Original image exists):

info: {
UIImagePickerControllerMediaType = "public.image";
UIImagePickerControllerOriginalImage = "<UIImage: 0x6b6b4e0>";
UIImagePickerControllerReferenceURL = "assets-library://asset/asset.JPG?id=39D9190B-064F-4C80-9B93-B4CA4FE01B22&ext=JPG";
}

iPad and iPad simulator (Compatibility mode) log: (there is no Original Image!)

 info: {
UIImagePickerControllerMediaType = "public.image";
UIImagePickerControllerReferenceURL = "assets-library://asset/asset.JPG?id=72AF462A-A8CE-4474-9535-B59A3154087D&ext=JPG";
}

Any ideas on why this is happening? I really need the iPad image.

I tried getting the image from the assets library (am i doing this correctly?), but the image is null.

NSURL *imageSource = [info objectForKey:UIImagePickerControllerReferenceURL];
UIImage *image1 = [[UIImage alloc] initWithContentsOfFile:[imageSource absoluteString]];

Thank you for any suggestions.

EDIT: I tried building the application in the iPad 4.3 simulator. Here there are no problems in retrieving the image - the original image exists in the info dictionary. Is there another way to do it in IOS 5?


回答1:


If you're sure the iPad has the image, it sounds like a bug.

But since you can get the reference url, you can use ALAsset API to get the image.

sorry, it should be ALAssets.

For your reference,


- (void)assetForURL:(NSURL *)assetURL resultBlock:(ALAssetsLibraryAssetForURLResultBlock)resultBlock failureBlock:(ALAssetsLibraryAccessFailureBlock)failureBlock

it is a method of ALAssetsLibrary.

For more, you can check the document from Apple.



来源:https://stackoverflow.com/questions/8171713/image-not-returned-by-didfinishpickingmediawithinfo

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!