2015-04-04 73 views

回答

4

回答我自己的問題。內存有效和快速的方式獲得GPS元數據是

let options = [kCGImageSourceShouldCache as String: kCFBooleanFalse] 
if let data = NSData(contentsOfURL: url), imgSrc = CGImageSourceCreateWithData(data, options) { 
    let metadata = CGImageSourceCopyPropertiesAtIndex(imgSrc, 0, options) as Dictionary 
    let gpsData = metadata[kCGImagePropertyGPSDictionary] as? [String : AnyObject] 
} 

第二個選項是

if let img = CIImage(contentsOfURL: url), metadata = img.properties(), 
gpsData = metadata[kCGImagePropertyGPSDictionary] as? [String : AnyObject] { … } 

它看起來更好斯威夫特但會佔用更多的內存(通過探查測試)。

0

更新版本雨燕3:

let options = [kCGImageSourceShouldCache as String: kCFBooleanFalse] 
if let data = NSData(contentsOfURL: url), let imgSrc = CGImageSourceCreateWithData(data, options as CFDictionary) { 
    let metadata = CGImageSourceCopyPropertiesAtIndex(imgSrc, 0, options as CFDictionary) as? [String : AnyObject] 
    if let gpsData = metadata?[kCGImagePropertyGPSDictionary as String] { 
     //do interesting stuff here 
    } 
}