美文网首页
保存图片至相册

保存图片至相册

作者: 古月思吉 | 来源:发表于2018-12-07 18:34 被阅读0次
  • 保存图片至相册功能需要注意,需要将 NSPhotoLibraryAddUsageDescription 授权请求添加到Info.plist文件中。不然在调用保存图片API时,app会闪退,并报错:
    This app has crashed because it attempted to access privacy-sensitive data without a usage description. The app's Info.plist must contain an NSPhotoLibraryAddUsageDescription key with a string value explaining to the user how the app uses this data.
Info.plist文件的配置

代码:

//保存图片至相册
UIImageWriteToSavedPhotosAlbum(finalImage, self, #selector(self.image(image:didFinishSavingWithError:contextInfo:)), nil)

/// 图片保存成功或失败的回调方法
@objc func image(image:UIImage,didFinishSavingWithError error:NSError?,contextInfo:AnyObject) {
    if error != nil {
        //...保存图片失败
    } else {
        //...保存图片成功
    }
}

相关文章

网友评论

      本文标题:保存图片至相册

      本文链接:https://www.haomeiwen.com/subject/wprxhqtx.html