使用imagepickercontroller从相机拍摄后,如何获取照片的时间和日期? 我试过环顾四周,但没有设法找到解决方案。
以下是我的代码,我可以在哪里调用didfinishpickingmediawithinfo
dispatch_async(self.sessionQueue, {
self.stillImageOutput?.connectionWithMediaType(AVMediaTypeVideo).videoOrientation = (self.previewView.layer as! AVCaptureVideoPreviewLayer).connection.videoOrientation
self.stillImageOutput!.captureStillImageAsynchronouslyFromConnection(self.stillImageOutput!.connectionWithMediaType(AVMediaTypeVideo), completionHandler: {
(imageDataSampleBuffer: CMSampleBuffer!, error: NSError!) in
if error == nil {
let data:NSData = AVCaptureStillImageOutput.jpegStillImageNSDataRepresentation(imageDataSampleBuffer)
let image:UIImage = UIImage( data: data)!
let libaray:ALAssetsLibrary = ALAssetsLibrary()
let orientation: ALAssetOrientation = ALAssetOrientation(rawValue: image.imageOrientation.rawValue)!
libaray.writeImageToSavedPhotosAlbum(image.CGImage, orientation: orientation, completionBlock: nil)
//pass the image to preview view controller for confirmation
self.snappedImage = image
self.performSegueWithIdentifier("previewPhoto", sender: self)
}else{
// print("Did not capture still image")
print(error)
}
})
})
答案 0 :(得分:0)
UIImagePickerControllerDelegate
包含以下方法:- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
info
字典具有一组预定义的键,这些键将返回与所选图像关联的众多对象。你想要的是UIImagePickerControllerMediaMetadata
。这将返回一个字典,其中包含拍摄图像的日期/时间。
答案 1 :(得分:0)
您可以简单地将let currentDate = NSDate()
放入captureStillImageAsynchronouslyFromConnection
功能的完成功能块中,以获取图像捕获回叫的日期和时间!