2017-06-03 140 views

回答

0

ALAssetsLibrary已棄用。你應該使用PhotosLibrary。

Assets Library框架自iOS 9.0起棄用。相反,使用照片框架,而iOS 8.0和更高版本則提供更多功能和更好的性能來處理用戶的照片庫。有關更多信息,請參閱照片。 在Photos框架中,PHPhotoLibrary類管理對照片庫的訪問和更改,而PHAsset和PHCollection類以及相關類上的類方法提供了查找照片和視頻資源的功能。

看到這個https://developer.apple.com/documentation/photos/phphotolibrary

這裏是保存視頻到相機膠捲,給你的URL保存視頻的示例代碼。

var placeHolder : PHObjectPlaceholder? 
PHPhotoLibrary.shared().performChanges({ 

    let creationRequest = PHAssetChangeRequest.creationRequestForAssetFromVideo(atFileURL: URL(string: videoPath)!) 
    placeHolder = creationRequest?.placeholderForCreatedAsset 

    }, completionHandler: { (success, error) in 
     if success { 

      let result = PHAsset.fetchAssets(withLocalIdentifiers: [placeHolder!.localIdentifier], options: nil) 
      result.firstObject?.getURL(completionHandler: { url in 

       // this is the url to the saved asset 

      }) 
     } 
}) 

不要忘記

import Photos 

,並添加該代碼作爲擴展PHAsset:

https://gist.github.com/jVirus/2f041bb8b1936093773f0bde42af3a49

相關問題