Quang Nguyễn
Quang Nguyễn

Reputation: 11

Save GIF image from URL to Camera Roll

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!

Upvotes: 1

Views: 2695

Answers (2)

Bleiki
Bleiki

Reputation: 61

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))
        }
    }

Upvotes: 3

guidev
guidev

Reputation: 2875

Try this:

import AssetsLibrary


let image = NSData(contentsOfURL: url)

ALAssetsLibrary().writeImageDataToSavedPhotosAlbum(image, metadata: nil, completionBlock: { (assetURL: NSURL!, error: NSError!) -> Void in
        print(assetURL)
})

Upvotes: 0

Related Questions