在我的IBACTION上使用以下代码将我的UIImageview> UIImage> PNG放入照片中
但是,当我按IBACTION时,图像不在我的画廊中
UIGraphicsBeginImageContextWithOptions(self.theView.bounds.size, view.isOpaque, 0)
theView.layer.render(in: UIGraphicsGetCurrentContext()!)
let theCapturedImage = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
let data = theCapturedImage!.pngData()
let url = NSURL(fileURLWithPath: NSTemporaryDirectory()).appendingPathComponent(NSUUID().uuidString+".dat")
do {
try data!.write(to: url!, options: [])
} catch let e as NSError {
print("Error! \(e)");
return
答案 0 :(得分:0)
而不是将数据写入临时目录,请在do
块中尝试以下操作:
let image = UIImage(data: data)
UIImageWriteToSavedPhotosAlbum(data, nil, nil, nil)
通过在Privacy - Photo Library Usage Description
中设置带有适当说明的info.plist
键,请记住要保存到图库中所需的权限。