1

I'm trying to save a GIF from URL to Camera Roll with the following code:

var image = UIImage(data: NSData(contentsOfURL: self.imageView.sd_imageURL())!)
UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil)

but after saving, the GIF become a still image, anyone can help me? Thanks!

  • possible duplicate of [How to write animated GIF to iOS camera roll?](http://stackoverflow.com/questions/17499513/how-to-write-animated-gif-to-ios-camera-roll) – dandan78 Aug 24 '15 at 15:42

2 Answers2

2

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 {
            completion(.failure(error))
        } else {
            completion(.success(true))
        }
    }
Bleiki
  • 41
  • 4
0

Try this:

import AssetsLibrary


let image = NSData(contentsOfURL: url)

ALAssetsLibrary().writeImageDataToSavedPhotosAlbum(image, metadata: nil, completionBlock: { (assetURL: NSURL!, error: NSError!) -> Void in
        print(assetURL)
})
guidev
  • 2,695
  • 2
  • 23
  • 44