for (NSDictionary *dictin info) {
if ([dictobjectForKey:UIImagePickerControllerMediaType] ==ALAssetTypePhoto){
if ([dictobjectForKey:UIImagePickerControllerOriginalImage]){
UIImage* image=[dictobjectForKey:UIImagePickerControllerOriginalImage];
[images addObject:image];
//獲取圖片名稱
__blockNSString *imageName = [NSStringnew];
ALAssetsLibraryAssetForURLResultBlock resultblock = ^(ALAsset *myasset){
ALAssetRepresentation *representation = [myassetdefaultRepresentation];
imageName = [representation filename];
NSLog(@"fileName : %@",imageName);
};
//注意這個地方,網上大多數用的是系統的類,單張選中,所以這個地方會是info,所以如果直接網上覆制的代碼,運行之後,會報錯,需要改成dict
NSURL *imageURL = [dictvalueForKey:UIImagePickerControllerReferenceURL];
ALAssetsLibrary* assetslibrary = [[ALAssetsLibraryalloc] init];
[assetslibrary assetForURL:imageURL
resultBlock:resultblock
failureBlock:nil];
[selfdismissViewControllerAnimated:YEScompletion:^{
//獲取圖片的類型前的名字,將字符串切割操作
NSString *imagePath = [[imageNamecomponentsSeparatedByString:@"."]
firstObject];
NSString *aPath=[NSStringstringWithFormat:@"%@/Documents/%@.jpg",
NSHomeDirectory(),imagePath];
NSData *imgData =UIImageJPEGRepresentation(image,0);
//將圖片寫入沙盒
[imgData writeToFile:aPathatomically:YES];
NSLog(@"path == %@ ==%@",imagePath,aPath);
}];
} else {
NSLog(@"UIImagePickerControllerReferenceURL = %@", dict);
}
} elseif ([dict objectForKey:UIImagePickerControllerMediaType] ==ALAssetTypeVideo){
}