iOS UIImagePickerController:获取所选图片日期的任何方式? [英] iOS UIImagePickerController: Any way of getting the date of the chosen Picture?

查看:84
本文介绍了iOS UIImagePickerController:获取所选图片日期的任何方式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,我使用的是一个UIImagePickerController,它调用

Within my application I am using an UIImagePickerController which calls

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

成功。
问题是,我需要拍摄图像的日期。如果用户拍摄新照片,我当然可以拍摄当前日期,但如果用户从相机胶卷或其他保存的照片中选择了照片,我该怎么办?

on success. The thing is, i need the date at which the image was taken. If the user shot a new picture i can take the current date of course, but what can I do in case the user chose a picture from his camera roll or another saved picture?

推荐答案

您可以将此代码用于从相册中提取的照片和视频。 info 是上述委托方法中的第二个参数。

You can use this code for photos and videos fetched from albums. info is second parameter in the mentioned delegate method.

NSURL *mediaUrl = info[UIImagePickerControllerReferenceURL];
ALAssetsLibrary *assetsLibrary = [[ALAssetsLibrary alloc] init];

[assetsLibrary assetForURL:mediaUrl resultBlock:^(ALAsset *asset) {
    NSDate *date = [asset valueForProperty:ALAssetPropertyDate];
    // ...
} failureBlock:nil];

同样,要使其工作,您需要包括项目 AssetsLibrary 框架。

As well, to make it work you need to include to project AssetsLibrary framework.

这篇关于iOS UIImagePickerController:获取所选图片日期的任何方式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆