【发布时间】:2021-01-19 16:29:16
【问题描述】:
我想将一些文件(声音、文本等)从 iOS 应用程序传输到文件应用程序。此外,我想将所有这些项目放入与我的应用程序同名的文件夹中 - 例如 GarageBand 或 KeyNote。
在 Xcode 中,我确实启用了 iCloud 文档功能 - 我还定义了一个容器“iCloud.xxx.yyy” - 请参见下面的代码。
guard let fileURL = Bundle.main.url(forResource: "test", withExtension: "aiff") else { return }
guard let containerURL = FileManager.default.url(forUbiquityContainerIdentifier: "iCloud.xxx.yyy") else { return }
if !FileManager.default.fileExists(atPath: containerURL.path) {
try FileManager.default.createDirectory(at: containerURL, withIntermediateDirectories: true, attributes: nil)
}
let backupFileURL = containerURL.appendingPathComponent("test.aiff")
if FileManager.default.fileExists(atPath: backupFileURL.path) {
try FileManager.default.removeItem(at: backupFileURL)
try FileManager.default.copyItem(at: fileURL, to: backupFileURL)
} else {
try FileManager.default.copyItem(at: fileURL, to: backupFileURL)
}
当我运行我的代码时,它似乎可以工作 - 无论如何,我看不到代表我的应用程序名称的文件夹,也看不到文件应用程序中的“test.aiff”文件。我的方法有什么问题?
【问题讨论】:
-
文件应用程序 = Finder?记录 containerURL,然后按 command + shift + G 在 Finder 中导航到它。它在那里吗?日志甚至显示吗?
-
不,我的意思是文件应用程序中的 iCloud Drive
-
好的,现在您使用的是 iOS。您可能应该添加您的问题。
-
好的,我会改正的
标签: ios swift icloud file-transfer ubiquitycontainer