Saving a File to Icloud Drive

Saving a file to icloud drive

You have to check and create "Documents" folder and also it's good practice to handle errors:

if let containerUrl = FileManager.default.url(forUbiquityContainerIdentifier: nil)?.appendingPathComponent("Documents") {
if !FileManager.default.fileExists(atPath: containerUrl.path, isDirectory: nil) {
do {
try FileManager.default.createDirectory(at: containerUrl, withIntermediateDirectories: true, attributes: nil)
}
catch {
print(error.localizedDescription)
}
}

let fileUrl = containerUrl.appendingPathComponent("hello.txt")
do {
try "Hello iCloud!".write(to: fileUrl, atomically: true, encoding: .utf8)
}
catch {
print(error.localizedDescription)
}
}

Swift - saving a file to icloud drive

I resolved the issue by naming the icloud bucket with the same name as bundle id of the app -> then upgrading the version number of the app

Save PDF file to a user-defined default directory in iCloud Drive

Yes you can. Using UIDocumentPickerViewController you can ask for a directory, and you can save it in your app. This is explained in detail in Providing Access to Directories. iOS 13 and later.

See also What's New in File Management and Quick Look for sample code saving a directory URL and then reusing it to set the base directory for a subsequent call to UIDocumentPickerViewController

Swift write/save/move a document file to iCloud drive

I had this problem. I followed the advice here and I found that my Info.plist key was not correct. Once I changed it to iCloud.MY_BUNDLE_IDENTIFIER (i.e. copy the string from the CFBundleIdentifier key higher in Info.plist) it all started working.

Removing the .com from your key may fix your issue.



Related Topics



Leave a reply



Submit