Save gif to iOS Photo Library in Swift

拜拜、爱过 提交于 2019-12-07 13:30:47

问题


I'm traing to save a GIF image located in temp file already created with Regift code.

Regift: https://github.com/matthewpalmer/Regift

The thing is that after saving with PHPhotoLibrary the GIF become a still image.

In other questions there's answers that refeer AssetsLibrary but this has been deprecated by Apple and doesn't work for iOS 10.

Questions:

Save GIF image from URL to Camera Roll

How to write animated GIF to iOS camera roll?

None of this answers works... I just want to convert an image to gif and save it to camera roll... Any help?

Thanks


回答1:


You can save GIF via PHPhotoLibrary.

PHPhotoLibrary.shared().performChanges({
    let request = PHAssetCreationRequest.forAsset()
    request.addResource(with: .photo, fileURL: 'YOUR_GIF_URL', options: nil)
}) { (success, error) in
    if let error = error {
        print(error.localizedDescription)
    } else {
        print("GIF has saved")
    }
}



回答2:


Gif can be save through Activity ViewController. Give url in activity controller and save through that you will get gif in camera roll [https://www.youtube.com/watch?v=-DdXUIjuAk0&feature=youtu.be]

let activityViewController = UIActivityViewController(
        activityItems: [url],
        applicationActivities: nil)

    activityViewController.popoverPresentationController?.sourceView = view
    activityViewController.popoverPresentationController?.sourceRect = view.frame
    present(activityViewController, animated: true, completion: nil)


来源:https://stackoverflow.com/questions/43927287/save-gif-to-ios-photo-library-in-swift

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!