2017-06-03 138 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

相关问题