I have successfully saved and loaded documents to and from the user's iCloud Drive using iCloud documents, but the document is visible in the user's iCloud Drive, like this:
I do not want this, as this is saved data from my app. Is there any way to keep these documents hidden?
Here is my code:
var containerUrl: URL? {
return FileManager.default.url(forUbiquityContainerIdentifier: nil)?.appendingPathComponent("Documents")
}
func read() -> String {
let documentUrl = self.containerUrl!.appendingPathComponent("test.txt")
print("url: \(documentUrl)")
do {
return try String(contentsOf: documentUrl)
}
catch {
alert(text: error.localizedDescription)
return "Error"
}
}
func save(text:String) {
if let url = self.containerUrl, !FileManager.default.fileExists(atPath: url.path, isDirectory: nil) {
do {
try FileManager.default.createDirectory(at: url, withIntermediateDirectories: true, attributes: nil)
}
catch {
alert(text: error.localizedDescription)
}
}
let documentUrl = self.containerUrl!.appendingPathComponent("test.txt")
print("url: \(documentUrl)")
do {
try text.write(to: documentUrl, atomically: true, encoding: .utf8)
}
catch {
alert(text: error.localizedDescription)
}
}
and what I added to my Info.plist:
<key>NSUbiquitousContainers</key>
<dict>
<key>iCloud.testCloudStorage</key>
<dict>
<key>NSUbiquitousContainerIsDocumentScopePublic</key>
<true/>
<key>NSUbiquitousContainerName</key>
<string>testCloudStorage</string>
<key>NSUbiquitousContainerSupportedFolderLevels</key>
<string>Any</string>
</dict>
</dict>
Any help would be appreciated.