Saturday, November 7, 2026
HomeiOS Developmentios - Sending file to iCloud

ios – Sending file to iCloud

[ad_1]

It is a drawback I couldn’t discover a passable answer anyplace (together with right here). I simply need to add a textual content file created in my app to a folder in iCloud, the place I will be utilizing it for different functions. As far I may study, this may very well be completed by (1) setting iCloud capabilities in app goal Signing&Capabilities, (2) offering the mandatory entry for NSUbiquitousContainers in plist, and (3) get the url for the UbiquitousContainer in my app because the handle the place to ship my file (with some modifications).

To be able to check this scheme, I arrange a quite simple check app named SaveToiCloud, wherein I’ve:

1 – iCloud Signing&Capabilities:

enter image description here

2 – entry added plist:

<key>NSUbiquitousContainers</key>
    <dict>
        <key>iCloud.com.oscarjs.SaveToiCloud</key>
        <dict>
            <key>NSUbiquitousContainerIsDocumentScopePublic</key>
            <true/>
            <key>NSUbiquitousContainerName</key>
            <string>SaveToiCloud</string>
            <key>NSUbiquitousContainerSupportedFolderLevels</key>
            <string>Any</string>
        </dict>
    </dict>
  1. ViewController:

    import UIKit

    class ViewController: UIViewController {

     override func viewDidLoad() {
         tremendous.viewDidLoad()
    
         let path = FileManager.default.url(forUbiquityContainerIdentifier: nil)?.appendingPathComponent("Paperwork")
         let filePath = path!.appendingPathComponent("check.txt")
         do {
             attempt? "Good day world".knowledge(utilizing: .utf8)?.write(to: filePath)
         } catch {
             print(error)
         }
     }
    

    }

So, when a run the app, it crashes on the line under, as a result of path is nil. Regardless of I attempted many options, the outcomes had been at all times getting path = nil. For all I may collect, the issue appears associated to the plist entry, for whicht I couldn’t discover a answer, however perhaps I am flawed with this guess. Can anybody assist me?

let filePath = path!.appendingPathComponent("check.txt")

[ad_2]

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments