2017-06-21 83 views

回答

3

我不知道如何創建從視頻對象PHAsset但是當你可以做到這一點,

我找到了解決create a PHAsset from an Video

碼塊1:

PhotoLibrary.shared().performChanges({ 
    let createAssetRequest = PHAssetChangeRequest.creationRequestForAssetFromVideoAtFileURL(/*Your url here*/) 
    placeholder = createAssetRequest.placeholderForCreatedAsset 
    identifier = placeholder.localIdentifier 
}, completionHandler: { 
    success, error in 
    /* 
     Fetch Asset with the identifier here 
     after that, add the PHAsset into an album 
    */ 
    newAsset = PHAsset.fetchAssets(withLocalIdentifiers: [identifier], options: nil).firstObject 
} 

你可以用下面的代碼片段添加PHAsset

碼塊2:

PhotoLibrary.shared().performChanges({ 

    guard let addAssetRequest = PHAssetCollectionChangeRequest(for: /*your specific album here as PHAssetCollection*/) else { return } 

    addAssetRequest.addAssets([newAsset] as NSArray) 
}, completionHandler: { 
    success, error in 
    //handle error or stuff you want to do after that here 
}) 

EDIT實施例用於創建PHAssetCollection

在這種情況下,我取出的創建PHAssetCollection它在performChanges(_:,completionHandler:)閉合創建之後,並把它在該功能的關閉@escaping

PHPhotoLibrary.shared().performChanges({ 

     let createRequest = PHAssetCollectionChangeRequest.creationRequestForAssetCollection(withTitle: name) 
     placeHolderIdentifier = createRequest.placeholderForCreatedAssetCollection.localIdentifier 

    }, completionHandler: { 
     success, error in 
     if success { 
      var createdCollection: PHAssetCollection? = nil 
      if placeHolderIdentifier != nil { 
       createdCollection = PHAssetCollection.fetchAssetCollections(withLocalIdentifiers: [placeHolderIdentifier!], options: nil).firstObject 
      } 
      completion(success, createdCollection as? T) 
     } else { 
      LogError("\(error)") 
      completion(success, nil) 
     } 
    }) 
+0

感謝您的支持。我會檢查並通知你。 –

+0

@Ankit庫馬爾古普塔是如此的工作?還是你還在與...打交道? –

+0

對不起@Marcel本週還有其他一些優先事項。一定會測試它,並讓你知道在下一個。 –

相關問題