我从UIImagePickerController中选择了图像,之后我获得了其委托方法的信息字典。我想从NSURL获取图像名称请为iOS 9建议代码,因为不推荐使用ALAsset库代码来获取图像名称。
NSURL *imageURL = [info valueForKey:UIImagePickerControllerReferenceURL];
答案 0 :(得分:0)
导入资产库
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
// selected image
UIImage *chosenImage = info[UIImagePickerControllerEditedImage];
self.img_profilepic.image = chosenImage;
// NSString *setimageName;
// get the ref url
NSURL *refURL = [info valueForKey:UIImagePickerControllerReferenceURL];
// define the block to call when we get the asset based on the url (below)
ALAssetsLibraryAssetForURLResultBlock resultblock = ^(ALAsset *imageAsset)
{
ALAssetRepresentation *imageRep = [imageAsset defaultRepresentation];
NSLog(@"[imageRep filename] : %@", [imageRep filename]);
[self cstmGetUploadImageName:[imageRep filename]];
};
// get the asset library and fetch the asset based on the ref url (pass in block above)
ALAssetsLibrary* assetslibrary = [[ALAssetsLibrary alloc] init];
[assetslibrary assetForURL:refURL resultBlock:resultblock failureBlock:nil];
// upload image method
//[self cstmUploadImage:chosenImage withName:@"sdf"];
[picker dismissViewControllerAnimated:YES completion:NULL];
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
[picker dismissViewControllerAnimated:YES completion:NULL];
}
-(void)cstmGetUploadImageName:(NSString *)filename{
NSString *tempFileName = filename;
NSLog(@"%@",tempFileName);
}