Writing to iCloud drive

I need to write files to iCloud drive from my ionic cordova app. I’ve tried the cordova-file-plugin and I could save any file to the paths that are reported to be synced to iCloud like e.g. cordova.file.syncedDataDirectory or cordova.file.documentsDirectory. However, the files are not synced at all to my other devices for the tested app. I suppose the paths are not exactly synced at once like I would expect, but synced only when a backup is done.

So, is there a way (a plugin or library) able to put a file on the iCloud drive from a cordova app so that the file is immediately synced with other devices connected to the same iCloud account and not just on backup?

1 Like

have same problem, may be you found solution ?

Unfortunately I gave up and went for Dropbox and Google Drive.

1 Like

Have same problem, anyone found solution ?

cordova-plugin-file maybe can’t save icloud drive.
Instead of


syncedDataDirectory(for iOS) is private.

so I use social sharing.

  1. save file in temp dir.
  2. share icloud.
    let dir = this.file.tempDirectory;
    let fileName = ""; // please set your fileName;
    let blob = ""; // please set your data;

    try {
      this.file
        .writeFile(dir,
          fileName,
          blob,
          {replace: true})
        .then(value => {
          this.socialSharing.share(null, null, null, value.nativeURL);
        });
    } catch (e) {
      console.log(e);
    }
1 Like

Thanks @d-okuno. This solution works. But after moving the files to any cloud apps like iCloud or Google drive, the files were not be viewable. So I altered your solution like below.

try {
        this.socialSharing.share(null, null,FILE_NATIVE_URL, null).then(e =>{
                              console.log("SUCCESS IN SHARING",e)
        }).catch(e =>{
                              console.log("FAILURE IN SHARING",e)
       })
 } catch (e) {
       console.log("ERROR IN SAVING TO CLOUD",e);
  }
1 Like