2017-06-16 35 views
0

我正在開發Apple Photos Extension。我需要從PHAsset中獲取照片HDR和深度效果標誌。該擴展似乎只給了一個臨時映像文件的URL,而不是對PHAsset的引用。換句話說,我需要從擴展圖像URL(或其他方式)獲取PHAsset的對象,以便獲得HDR和深度效果屬性。如何從iOS Extension中的圖像URL獲取對PHAsset的引用?

for item: Any in self.extensionContext!.inputItems { 
let inputItem = item as! NSExtensionItem 
for provider: Any in inputItem.attachments! { 
     let itemProvider = provider as! NSItemProvider 
    if itemProvider.hasItemConformingToTypeIdentifier(kUTTypeImage as String) { ...... 

太感謝你了,

的Piyush

+0

文件的具體常數進行訪問:///var/mobile/Media/DCIM/100APPLE/IMG_0007.PNG有沒有遇到URL喜歡這個 ? –

+0

不,我有臨時目錄的網址 –

回答

0

據我所知深度(100%)和HDR(不知道:P)是在圖像屬性。所以這樣做是爲了讓他們:

let options = PHContentEditingInputRequestOptions() 
//for icloud or itunes 
options.isNetworkAccessAllowed = true 

//self is the PHAsset Object here this snippet is from an extenstion I made.    
self.requestContentEditingInput(with: options, completionHandler: { 
       (contentEditingInput, _) -> Void in 
    if contentEditingInput != nil { 
     if let url = contentEditingInput?.fullSizeImageURL { 
     //URL is the path of the File in the 
      if let imageSource = CGImageSourceCreateWithURL(url, nil) { 
       if let imageProperties = CGImageSourceCopyPropertiesAtIndex(imageSource, 0, nil) as Dictionary? { 
        //Now you can access the metadata here depth should be in exif afaik 
       } 
      } 
     } 
    } 
} 

不同Metadatas可以通過Image I/O

+0

嗨,我想從「contentEditingInput?.fullSizeImageURL」獲取PHAssest對象。 –

+0

我不確定,如果我理解你是對的。你只是想訪問數據?那麼'imageSource = CGImageSourceCreateWithURL(url,nil)'其中URL是'contentEditingInput!.fullSizeImageUrl'將是最好的方法。 –

+0

@PiyushParsaniya你還在苦於元數據嗎?你需要額外的幫助嗎? –

相關問題