Swift3 Swift 3-只能提取极少的EXIF数据

Swift3 Swift 3-只能提取极少的EXIF数据,swift3,Swift3,我是Swift新手,我正在尝试使用Swift 3为iOS开发EXIF查看器。目前,我只能从图像中提取极少量的数据ColorModel、Depth、PixelHeight、PixelWidth、ProfileName等,但我的Macbook和iPhone上的同一图像包含更多的EXIF 故事板1: 用户从摄影机卷中选择图像,然后单击“使用”按钮 情节提要2:处理图像并在表视图中显示EXIF数据 现在回答这个问题有点晚了,但如果有帮助的话: import Photos import PhotosUI

我是Swift新手,我正在尝试使用Swift 3为iOS开发EXIF查看器。目前,我只能从图像中提取极少量的数据ColorModel、Depth、PixelHeight、PixelWidth、ProfileName等,但我的Macbook和iPhone上的同一图像包含更多的EXIF

故事板1: 用户从摄影机卷中选择图像,然后单击“使用”按钮

情节提要2:处理图像并在表视图中显示EXIF数据


现在回答这个问题有点晚了,但如果有帮助的话:

import Photos 
import PhotosUI

 func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {

        let assetURL = info[UIImagePickerControllerReferenceURL] as! NSURL
        let asset = PHAsset.fetchAssets(withALAssetURLs: [assetURL as URL], options: nil)
        guard let result = asset.firstObject else {
            return
        }

        let imageManager = PHImageManager.default()
        imageManager.requestImageData(for: result , options: nil, resultHandler:{
            (data, responseString, imageOriet, info) -> Void in
            let imageData: NSData = data! as NSData
            if let imageSource = CGImageSourceCreateWithData(imageData, nil) {
                let imageProperties2 = CGImageSourceCopyPropertiesAtIndex(imageSource, 0, nil)! as NSDictionary
                print("imageProperties2: ", imageProperties2)
            }

        })
        dismiss(animated: true, completion: nil)
    }
class ExifDataViewController: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate {
    override func viewDidLoad() {
        super.viewDidLoad()
        for item in arrayEXIFDictionaryKeys {
            extractExifPropertyFromNSData(selectionAsNSData: ExifDataViewController.currentActiveImage, nameOfExifProperty: item as! String)
        }
    }
    override func didReceiveMemoryWarning() {super.didReceiveMemoryWarning()}

    // OUTLETS


    // VARIABLES DECLARATION
    static var currentActiveImage = NSData()

    // ARRAY PROPERTIES
    let arrayEXIFDictionaryKeys = [
        kCGImagePropertyExifExposureTime,
        kCGImagePropertyExifFNumber,
        kCGImagePropertyExifExposureProgram,
        kCGImagePropertyExifSpectralSensitivity,
        kCGImagePropertyExifISOSpeedRatings,
        kCGImagePropertyExifOECF,
        kCGImagePropertyExifVersion,
        kCGImagePropertyExifDateTimeOriginal,
        kCGImagePropertyExifDateTimeDigitized,
        kCGImagePropertyExifComponentsConfiguration,
        kCGImagePropertyExifCompressedBitsPerPixel,
        kCGImagePropertyExifShutterSpeedValue,
        kCGImagePropertyExifApertureValue,
        kCGImagePropertyExifBrightnessValue,
        kCGImagePropertyExifExposureBiasValue,
        kCGImagePropertyExifMaxApertureValue,
        kCGImagePropertyExifSubjectDistance,
        kCGImagePropertyExifMeteringMode,
        kCGImagePropertyExifLightSource,
        kCGImagePropertyExifFlash,
        kCGImagePropertyExifFocalLength,
        kCGImagePropertyExifSubjectArea,
        kCGImagePropertyExifMakerNote,
        kCGImagePropertyExifUserComment,
        kCGImagePropertyExifSubsecTime,
        kCGImagePropertyExifSubsecTimeOriginal,
        kCGImagePropertyExifSubsecTimeDigitized,
        kCGImagePropertyExifFlashPixVersion,
        kCGImagePropertyExifColorSpace,
        kCGImagePropertyExifPixelXDimension,
        kCGImagePropertyExifPixelYDimension,
        kCGImagePropertyExifRelatedSoundFile,
        kCGImagePropertyExifFlashEnergy,
        kCGImagePropertyExifSpatialFrequencyResponse,
        kCGImagePropertyExifFocalPlaneXResolution,
        kCGImagePropertyExifFocalPlaneYResolution,
        kCGImagePropertyExifFocalPlaneResolutionUnit,
        kCGImagePropertyExifSubjectLocation,
        kCGImagePropertyExifExposureIndex,
        kCGImagePropertyExifSensingMethod,
        kCGImagePropertyExifFileSource,
        kCGImagePropertyExifCFAPattern,
        kCGImagePropertyExifCustomRendered,
        kCGImagePropertyExifExposureMode,
        kCGImagePropertyExifWhiteBalance,
        kCGImagePropertyExifDigitalZoomRatio,
        kCGImagePropertyExifFocalLenIn35mmFilm,
        kCGImagePropertyExifSceneCaptureType,
        kCGImagePropertyExifGainControl,
        kCGImagePropertyExifContrast,
        kCGImagePropertyExifSaturation,
        kCGImagePropertyExifSharpness,
        kCGImagePropertyExifDeviceSettingDescription,
        kCGImagePropertyExifSubjectDistRange,
        kCGImagePropertyExifImageUniqueID,
        kCGImagePropertyExifGamma,
        kCGImagePropertyExifCameraOwnerName,
        kCGImagePropertyExifBodySerialNumber,
        kCGImagePropertyExifLensSpecification,
        kCGImagePropertyExifLensMake,
        kCGImagePropertyExifLensModel,
        kCGImagePropertyExifLensSerialNumber] as [Any]

    let arrayIndividualImageProperties = [
        kCGImagePropertyDPIHeight,
        kCGImagePropertyDPIWidth,
        kCGImagePropertyPixelHeight,
        kCGImagePropertyPixelWidth,
        kCGImagePropertyDepth,
        kCGImagePropertyOrientation,
        kCGImagePropertyIsFloat,
        kCGImagePropertyIsIndexed,
        kCGImagePropertyHasAlpha,
        kCGImagePropertyColorModel,
        kCGImagePropertyProfileName] as [Any]

    // BACK TO SELECTION SCREEN
    @IBAction func returnToMain() {
        let storyboard = UIStoryboard(name: "Main", bundle: nil)
        let vc = storyboard.instantiateViewController(withIdentifier: "main") as UIViewController
        present(vc, animated: true, completion: nil)
    }

    // SHARE EXIF RESULTS
    @IBAction func shareImageResults() {

    }

    // GET EXIF PROPERTY
    func extractExifPropertyFromNSData(selectionAsNSData: NSData, nameOfExifProperty: String) {
        if let imageSource = CGImageSourceCreateWithData(selectionAsNSData as CFData, nil) {
            let imageProperties = CGImageSourceCopyPropertiesAtIndex(imageSource, 0, nil)
            let imageDictionary = NSMutableDictionary(dictionary: imageProperties!)
            print(imageProperties)
            addExifPropertyToTable(displayString: imageDictionary.dictionaryWithValues(forKeys: [nameOfExifProperty as String]))
        }
    }

    // ADD PROPERTY TO TABLE
    func addExifPropertyToTable(displayString: [String:Any]) {
        //print(displayString)
    }
}
import Photos 
import PhotosUI

 func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {

        let assetURL = info[UIImagePickerControllerReferenceURL] as! NSURL
        let asset = PHAsset.fetchAssets(withALAssetURLs: [assetURL as URL], options: nil)
        guard let result = asset.firstObject else {
            return
        }

        let imageManager = PHImageManager.default()
        imageManager.requestImageData(for: result , options: nil, resultHandler:{
            (data, responseString, imageOriet, info) -> Void in
            let imageData: NSData = data! as NSData
            if let imageSource = CGImageSourceCreateWithData(imageData, nil) {
                let imageProperties2 = CGImageSourceCopyPropertiesAtIndex(imageSource, 0, nil)! as NSDictionary
                print("imageProperties2: ", imageProperties2)
            }

        })
        dismiss(animated: true, completion: nil)
    }