我有这个简单的代码,我在macOS中与Catalyst一起运行:
struct ContentView: View {
@State private var pathURL = "/Users/cesare/Desktop/Test"
var body: some View {
VStack {
TextField("/Users/cesare/Desktop/Test", text: $pathURL)
.textFieldStyle(RoundedBorderTextFieldStyle())
.padding()
Button(action: {
let fileUrl = URL(fileURLWithPath: self.pathURL, isDirectory: true)
let nameImage = "ImageTest" + ".jpg"
let fileUrlWithName = fileUrl.appendingPathComponent(nameImage)
let imageData = UIImage(named: "2020-03-05_11-19-22_5")?.jpegData(compressionQuality: 1)
do {
try imageData!.write(to: fileUrlWithName)
} catch {
print("** saveImageData error: \(error.localizedDescription)")
}
}) {
Text("Save Image")
}
}
}
}
在Assets.xcassets
中放入2020-03-05_11-19-22_5
图像。当我按Save Image
按钮时,出现以下错误:You don’t have permission to save the file “ImageTest.jpg” in the folder “Test”.
为什么我没有在桌面上保存图像的权限?我试图导出“产品”中包含的应用程序,但未得到任何结果。我应该使用哪个路径将图像保存到Mac本地磁盘中?