如何从应用中下载JSON文件并移动至本地Shortcuts文件夹?
将自建应用中的JSON文件移动到本地Shortcuts文件夹的方法
针对应用开发者(自研自建应用)
iOS/iPadOS
利用系统文档选择器组件,引导用户将文件保存到Shortcuts文件夹:
- 获取JSON文件的本地存储URL
- 实例化
UIDocumentPickerViewController并设置导出模式 - 用户在弹出界面中找到「Shortcuts」文件夹完成保存
示例Swift代码片段:
// 替换为你的JSON文件实际存储URL let jsonFileURL = URL(fileURLWithPath: "/path/to/your/target.json") let picker = UIDocumentPickerViewController(forExporting: [jsonFileURL], asCopy: true) picker.delegate = self present(picker, animated: true)
macOS
直接通过文件管理API将文件复制到Shortcuts目录:
Shortcuts的默认本地路径为~/Library/Shortcuts/,使用FileManager完成拷贝操作即可。
示例Swift代码片段:
let sourceURL = URL(fileURLWithPath: "/path/to/your/json/file.json") let shortcutsDir = FileManager.default.urls(for: .libraryDirectory, in: .userDomainMask)[0] .appendingPathComponent("Shortcuts") let destURL = shortcutsDir.appendingPathComponent("your-custom-file.json") do { try FileManager.default.copyItem(at: sourceURL, to: destURL) } catch { print("文件复制失败: \(error.localizedDescription)") }
针对第三方工具创建的自建应用
- 优先查看应用自带功能:打开JSON文件后,寻找「导出」「分享」按钮,选择「保存到文件」,在文件应用中导航到「Shortcuts」文件夹完成存储。
- 若无导出选项,尝试系统共享菜单:长按或右键点击JSON文件,选择「共享」→「存储到文件」,指定Shortcuts文件夹即可完成转移。
内容的提问来源于stack exchange,提问作者Dragounow
相关产品推荐
相关产品推荐

