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
Cocoapods, Add Dependencies to All Targets in a Generic Way
Dismiss Keyboard with Swipe Gesture
Inputaccessoryview Animating Down When Alertcontroller (Actionsheet) Presented
App Groups Forsecurityapplicationgroupidentifier Returns Nil
Save Image with the Correct Orientation - Swift & Core Image
Double Tap Necessary to Select Tableview Item with Search Bar
Swift 2 Unused Constant Warning
Struggling to Convert Objective C Selector and Target Signature to Swift
Swift: Bring View from Stack View to Front
Skvideonode Only on a Small Part of Scnsphere
iOS Swift - Custom Camera Overlay
Swift iOS - Tag Collection View
Swift - Could Not Cast Value of Type 'Uitabbarcontroller'
Setting Uiimageview Image Affects Layout Constraints
Apple Push Notifications in Tvos
User Notification Request Always Come with Default Action Identifier