Skip to content

Instantly share code, notes, and snippets.

@SongJiaqiang
Last active October 16, 2019 05:39
Show Gist options
  • Save SongJiaqiang/a6f709c2f12a6e0a73a7db6583a70a4d to your computer and use it in GitHub Desktop.
Save SongJiaqiang/a6f709c2f12a6e0a73a7db6583a70a4d to your computer and use it in GitHub Desktop.
保存gif到相册
import AssetsLibrary
import MobileCoreServices
/// 保存gif图到相册
func saveGif2Album() {
let gifPath = Bundle.main.path(forResource: "name", ofType: "gif")
let gifData = NSData(contentsOfFile: gifPath!) as Data
let library = ALAssetsLibrary()
library.writeImageData(toSavedPhotosAlbum: gifData, metadata: nil, completionBlock: { (assetURL, error) in
DispatchQueue.main.async {
Toast.show(message: "gif图已保存到相册")
}
})
}
/// 拷贝gif到粘贴板
func copyGif2Pasteboard() {
let gifPath = Bundle.main.path(forResource: "name", ofType: "gif")
let gifData = NSData(contentsOfFile: gifPath!) as Data
UIPasteboard.general.setData(gifData, forPasteboardType: kUTTypeGIF as String)
Toast.show(message: "gif图已拷贝到粘贴板")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment