iOS 解决第一次保存GIF图片时,出现多张图片。

 ///保存GIF图片
    @objc class public func saveGifImage(imageUrl: URL){
        SDWebImageDownloader.shared.downloadImage(with: imageUrl, options: .useNSURLCache) { a, b, url in
            DispatchQueue.main.async {
                SVProgressHUD.show(withStatus: "保存中...")
            }
        } completed: { image, data, eror, isEnd in
            ///关键在于 0x47
            if let rImage = image,let data = data,([UInt8](data))[0] == 0x47 {
                PHPhotoLibrary.shared().performChanges({
                    if #available(iOS 9, *) {
                        let options = PHAssetResourceCreationOptions.init()
                        options.uniformTypeIdentifier = "com.compuserve.gif"
                        PHAssetCreationRequest.forAsset().addResource(with: .photo, data: data, options: options)
                    } else {
                        PHAssetChangeRequest.creationRequestForAsset(from: rImage)
                    }
                }) { isSucces, error in
                    DispatchQueue.main.async {
                        SVProgressHUD.dismiss()
                        SVProgressHUD.showInfo(withStatus:  isSucces ? "Gif图片保存成功" : "Gif图片保存失败")
                    }
                }
            }
        }
    }

你可能感兴趣的:(iOS 解决第一次保存GIF图片时,出现多张图片。)