如何在物镜c中获取照片创建日期 [英] How to get photo creation date in objective c
本文介绍了如何在物镜c中获取照片创建日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试从iPhone的图片库中选择图片时获取图片拍摄日期.我正在使用下面的代码来做同样的事情.
I am trying to get picture taken date while choosing picture from Photo Library in iPhone. I am using below code to do the same.
NSDictionary* fileAttribs = [[NSFileManager defaultManager] attributesOfItemAtPath:path error:nil];
NSDate *result = [fileAttribs fileCreationDate]; //or fileModificationDate
但是它显示的是当前日期和时间.
But it is showing current date and time.
从照片库中选择图片时,有什么方法可以获取拍摄日期.
Is there any way to get picture taken date while choosing picture from Photo library.
推荐答案
编辑,完整代码:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
NSURL *url = [info objectForKey:@"UIImagePickerControllerReferenceURL"];
ALAssetsLibrary* assetslibrary = [[ALAssetsLibrary alloc] init];
[assetslibrary assetForURL:url
resultBlock:^(ALAsset *asset) {
NSDate *myDate = [asset valueForProperty:ALAssetPropertyDate];
NSLog(@"Date: %@", myDate);
} failureBlock:^(NSError *error) {
NSLog(@"Error");
}];
[picker dismissViewControllerAnimated:YES completion:nil];
}
这篇关于如何在物镜c中获取照片创建日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文