How to get a NSDATE from UIImage?

2019-02-15 15:29发布

问题:

How do i get a date or metadata from a UIImage in this case:

//UIImagePickerControllerSourceType
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;

//delegate return
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{

// po info in console -> there is no metadata of the image where i can find the date
// Has anyone an idea how to get it?

}

回答1:

If you are referring to EXIF metadata in the image (which includes date information), you can see this question for information on how to access it:

How to access photo EXIF in pictures taken from camera in iOS 4.0+?



回答2:

The info dictionary contains a key called "UIImagePickerControllerMediaMetadata" which is another dictionary. Just NSLog allKeys of that to get the date key.



回答3:

NSDictionary *metadata = [info objectForKey: UIImagePickerControllerMediaMetadata];
NSLog(@"%@",metadata);

Choose what you need from metadata.