@ionic-native/file on iOS with ABORT_ERR

I’m using @ionic-native/file in my app to write a file using the following code inside a provider (or in the ts-file of the page directly):

writeFile(fileName, text) {
  // location
  if (this.isIOS) {
    this.fs = this.file.documentsDirectory;
  }
  if (this.isAndroid) {
    this.fs = this.file.externalRootDirectory;
  }

  return new Promise((resolve, reject) => {
    this.file.writeFile(this.fs, fileName, text, {replace: true})
      .then(content => resolve(content))
      .catch(err => console.log(err);
    )
  })
}

It is working without any problems on android, but on an iOS device (iPad) I’m getting the following error on log console:

{"code":3,"message":"ABORT_ERR"}

A few months ago it works with the same code. I don’t know where the problem is and how to solve it. Can you help me? Thanks in advance!

I found the problem myself: I used as filename a not existent directory. Without it, it’s working without any problem. Sorry…

I could not understand your solution. Can you please explain?

As I can remind, the problem was not in the code above, but that I used writeFile() with the wrong fileName. In Android I have to use it with the whole path and in iOS only with the name of the file.

Where is the documentsDirectory in iOS? I have downloaded the file successfully but can’t see the file in that directory?

Can you please look into this question?

The documentsDirectory is only accessible from your app. There’s a way to access files in iTunes and in the files app. To achieve this, I think it’s necessary to set UIFileSharingEnabled and LSSupportsOpeningDocumentsInPlace in the info plist of your app.

If i include UIFileSharingEnabled and LSSupportsOpeningDocumentsInPlace, then will i be able write file to a directory in iOS or i can directly share the file to dropbox or google drive?

I think, you can read and write a file without including anything. But the files written by your app can only be accessed by your app and nothing else.

If you include UIFileSharingEnabled you can access the documentsDirectory by iTunes on a connected computer and if you include LSSupportsOpeningDocumentsInPlace it can be accessed by the iOS files app. By this way I think, you can directly share the files to other apps like dropbox or google drive…