【问题标题】:SwiftUI Catalyst App in macOS computer - Which path should I use to save an image in my Mac local disk?macOS 计算机中的 SwiftUI Catalyst App - 我应该使用哪个路径将图像保存在我的 Mac 本地磁盘中?
【发布时间】:2020-07-16 18:01:12
【问题描述】:

我有这个简单的代码,我在 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 本地磁盘中?

【问题讨论】:

    标签: save swiftui catalyst


    【解决方案1】:

    要将文档保存在任何文件夹中,您需要将App Sandbox 设置为NO

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-06-03
      • 2019-06-14
      • 2019-07-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多