Fra*_*s F 1 macos file-manager macos-app-extension swift4.2 macos-mojave
在我的 macOS 应用程序中,我尝试使用以下扩展名创建一个目录
\n\nextension URL {\n static func createFolder(folderName: String, folderPath:URL) -> URL? {\n let fileManager = FileManager.default\n let folderURL = folderPath.appendingPathComponent(folderName)\n // If folder URL does not exist, create it\n if !fileManager.fileExists(atPath: folderURL.path) {\n do {\n // Attempt to create folder\n // try fileManager.createDirectory(at: folderURL, withIntermediateDirectories: true, attributes: nil)\n // try fileManager.createDirectory(atPath: folderURL.path, withIntermediateDirectories: true, attributes: nil)\n try fileManager.createDirectory(atPath: folderURL.relativePath, withIntermediateDirectories: true, attributes: nil)\n } catch {\n print(error.localizedDescription + ":\\(folderURL.path)")\n return nil\n }\n }\n return folderURL\n }\n}\nRun Code Online (Sandbox Code Playgroud)\n\n当我调用此调用时,它给我错误
\n\n\n\n\n您\xe2\x80\x99t无权将文件\xe2\x80\x9cFolderName\xe2\x80\x9d保存在文件夹\n\xe2\x80\x9cSelectedFolder\xe2\x80\x9d.:/Users/USERNAME/中工作区/选定文件夹/文件夹名称
\n
我看过类似的帖子并尝试了所有方法,但它仍然给我错误,我在这里遗漏了什么吗?任何帮助表示赞赏
\n小智 5
我假设您的应用程序是沙盒的。因此,您无权为您尝试写入的位置写入文件夹。
如果它不适用于沙盒,您可以禁用应用程序沙盒,可以通过单击项目文件>目标名称、选择功能选项卡并关闭应用程序沙盒来关闭它。
您还可以查看安全范围书签以获取持久资源访问。
文档在这里:
| 归档时间: |
|
| 查看次数: |
3550 次 |
| 最近记录: |