读取本地资产时出错。 assetURL具有所选图片的url,但是读取图片会生成错误并且NSData返回nil
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImagePickerControllerSourceType sourceType = [picker sourceType];
if ( sourceType != UIImagePickerControllerSourceTypeCamera )
{
//IT’S a local asset
NSURL *assetURL = [info objectForKey:UIImagePickerControllerReferenceURL];
NSError *error;
NSData *data = [NSData dataWithContentsOfURL:assetURL options:NSDataReadingMappedAlways error:&error];
if (error != nil)
{
NSLog(@“%@“,error.description);
/*
Error printed:
2014-07-10 10:45:16.447 ApplicationName[91958:60b]
Error Domain=NSCocoaErrorDomain
Code=256 "The operation couldn’t be completed. (Cocoa error 256.)"
UserInfo=0x112d15d00
{NSURL=assets-library://asset/asset.PNG?id=9FE11E80-805B-4EB9-88DC-EE9C3A3051EC&ext=PNG}
*/
}
else
{
self.image = [UIImage imageWithData:data];
}
}
}