- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想支持在我的 iOS 应用程序中将文件添加到 iCloud。我希望将这些文件添加到 iCloud Drive 上的文件夹中(例如 Numbers 或 Pages 文件夹)。我尝试了我在网上找到的关于这个主题的所有内容,但我没有设法将文件夹添加到 iCloud Drive。
首先,我将 NSUbiquitousContainers
添加到 info.plist
<key>NSUbiquitousContainers</key>
<dict>
<key>iCloud.com.<xyz>.AppName</key>
<dict>
<key>NSUbiquitousContainerIsDocumentScopePublic</key>
<true/>
<key>NSUbiquitousContainerName</key>
<string>App Name</string>
<key>NSUbiquitousContainerSupportedFolderLevels</key>
<string>Any</string>
</dict>
</dict>
然后,我将以下代码添加到我的 ViewController 中:
if let iCloudDocumentsURL = FileManager.default.url(forUbiquityContainerIdentifier: nil)?.appendingPathComponent("Documents") {
if (!FileManager.default.fileExists(atPath: iCloudDocumentsURL.path, isDirectory: nil)) {
do {
try FileManager.default.createDirectory(at: iCloudDocumentsURL, withIntermediateDirectories: true, attributes: nil)
} catch {
print(error.localizedDescription)
}
}
}
注意:设置断点后,我发现 if (!FileManager.default.fileExists(atPath: iCloudDocumentsURL.path, isDirectory: nil)) {
之后的代码永远不会被调用。我暂时删除了这一行,但这没有做任何事情。
最后,我使用以下代码添加了一个文件:
//Save text file to local directory
let file = "file.txt" //Text file to save to iCloud
let text = "sample text" //Text to write into the file
func saveToDirectory(){
guard let directory = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first else { return }
let fileURL = directory.appendingPathComponent(file)
print(directory)
//Writing
do {
try text.write(to: fileURL, atomically: false, encoding: .utf8)
} catch {
/* error handling here */
print("Error in writing")
}
//Reading
do {
let getText = try String(contentsOf: fileURL, encoding: .utf8)
print(getText)
} catch {
/* error handling here */
print("Error in reading")
}
}
我没有看到应用程序的文件夹,或者上述文件出现在我的 iCloud Drive 上。但是,当我下载应用程序容器并查看其内容时,我看到该文件列在 /AppData/Documents
下。
其他人有这个吗?和/或有人知道如何解决这个问题吗?
谢谢!
我还更改了我的应用程序的构建/版本号,但没有任何结果
最佳答案
您应该将文件复制到 iCloud 容器,您只是将其写入应用沙箱。
首先,在您的 iCloud 容器上创建 Documents
文件夹 - 如果您将文件存储在其他文件夹中,您在另一台设备上的应用程序将看到该文件夹,但它不会出现在文件应用程序中。
然后将您的 file.txt 复制到您的 iCloud 容器上的 Documents
文件夹中。
关于ios - 将 iCloud Drive 文件管理器添加到 App - iOS 13,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59802590/
如何在 C# 中检测两个文件是否完全相同(大小、内容等)? 最佳答案 这是一个简单的解决方案,它只读取两个文件并比较数据。它应该不会比散列方法慢,因为这两种方法都必须读取整个文件。 编辑 正如其他人所
我正在为我的工作编写一个简单的文档管理系统。我只是一个爱好者,但已经编程了一段时间了。我的问题是这样的。当我通过我的应用程序删除了一些文档时,我需要删除相关的数据库记录。如果抛出异常,最好的解决方法是
我已经使用 Xcode 一段时间了。一直困扰我的一件事是它处理文件的方式。我喜欢将我的文件全部放在嵌套文件夹中,而不是一个大的物理文件夹中,但是默认情况下,当您在 Xcode 中创建一个组时,它不会创
我正在使用 DNN 5.6.2,并且正在尝试构建一个自定义模块,用户可以在其中上传我对其运行验证的文件。如果文件有效,则将其保存。模块创建了一个根级目录“DataValidation”,并且模块的每个
我一直在尝试在某些目录中创建文件,但一直无法弄清楚。 重点是在包dir中创建文本文件:com.resources.files但我的想法不起作用。 public boolean archiveFile(
我们使用 Realm 一段时间了,我们的一些用户遇到了一些与 Realm 相关的数据丢失问题。我们认为我们已经将范围缩小到文件变得太大时的压缩方法。我们想就这是否是重新创建 Realm 文件的正确方法
我正在学习 Linux,我需要创建一个允许输入重定向 (stdin) 和输出重定向 (stdout) 的函数。我发现了一个示例,其中实际创建了一个文件文本,该文件文本的名称是我选择的名称。但是我不明白
我正在做我的学校作业,我遇到了我的第一个主要障碍......我无法写入文件,甚至无法使用 scanf 和 fgets 检索输入。 问题一: FILE *f1; char date_trans[100]
我的猜测是错误的,与答案无关。这个问题不再有效。请参阅my answer 。很抱歉这个糟糕的问题。 Tl;dr 版本 为什么 Java 进程无法找到某个文件,直到另一个进程(创建该文件的进程)完成执行
如何在 java 中过滤单引号 '? 我有一个搜索框,如果有人输入单引号,我会收到一个数据库错误。 我不想在 JavaScript 或数据库级别对其进行归档;我只想用 Java 来做。我该怎么做? 我
我是 ios 开发的新手,我遇到了与内存管理和处理大型数据集的方法有关的问题。 现在,我正在加载 csv 文件并将相关数据作为对象存储在应用程序初始化时的内存中。一些 csv 文件大于 1MB,我的应
我正在构建一个包含我自己的 *.c 和 *.h 文件的小型库,但我不确定应该如何管理它们,尤其是在将它们包含到项目中时。我在 Ubuntu 上使用 Codeblocks 以防万一。对于每个 .c/.h
我正在为我的数据结构编程课做大学作业。我们正在为这项任务分组工作,所以我目前正在处理我的一个队友项目。我添加了本地 READ/WRITE 代码,这样我就可以将数组列表保存到本地 .dat 文件中。但是
我在上传文件时使用数据库来命名文件,我的应用程序使用数据库来识别文件(用于视频流),因此它们需要相同。但是,如果上传失败,或者有人取消上传,我就会留下一个浪费的 ID。 加类 我有更多浪费的 ID 号
我的想法是创建一个包含服务的 .jar 文件 由 Spring 管理,应该由 getBean() 获取 我想把它放到 Web-app 的 WEB-INF/lib 然后在网络应用程序 Servlet 中
我在 Rails 开发中使用 SASS 文件。我想知道我是否应该gitignore 生成 CSS 文件。 在 Git 中添加 CSS 文件的问题在于它们只是多余的。public/stylesheets
我目前正在尝试编写一个 Maven 插件,它应该能够在“生成资源”阶段创建/处理一些资源文件。一切正常,但在此过程中我的插件需要读取一些其他文件作为输入,所以我决定使用 Apache Maven Fi
我是一名优秀的程序员,十分优秀!