macOS 计算机中的 SwiftUI Catalyst App - 我应该使用哪个路径将图像保存在我的 Mac 本地磁盘中? [英] SwiftUI Catalyst App in macOS computer - Which path should I use to save an image in my Mac local disk?
问题描述
我有这个简单的代码,我在 macOS 中使用 Catalyst 运行:
I have this simply code, that I run with Catalyst in macOS:
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
按钮时,出现此错误:您无权将文件ImageTest.jpg"保存在文件夹Test"中.
为什么我没有在桌面上保存图像的权限?我试图导出产品中包含的应用程序,但没有得到任何结果.我应该使用哪个路径在 Mac 本地磁盘中保存图像?
In Assets.xcassets
I put 2020-03-05_11-19-22_5
image. When I press Save Image
button, I have this error: You don’t have permission to save the file "ImageTest.jpg" in the folder "Test".
Why I don't have permission for save image in my Desktop?
I tried to export the app contained in Products, without getting any results.
Which path should I use to save an image in my Mac local disk?
推荐答案
要将文档保存在任意文件夹中,需要将 App Sandbox
设置为 NO
.
To save the document in any folder, you need to set the App Sandbox
to NO
.
这篇关于macOS 计算机中的 SwiftUI Catalyst App - 我应该使用哪个路径将图像保存在我的 Mac 本地磁盘中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!