cordova-plugin-file icon indicating copy to clipboard operation
cordova-plugin-file copied to clipboard

required info.plist adjustments are within scope of using this plugin but not discussed

Open John867530nine opened this issue 4 years ago • 2 comments

Regarding 6.0.2

Feature Request

Document this plugin's relationship to the mandatory *-info-plist options for iOS builds. It is necessary to manually adjust build options for an iOS target in order to gain equivalent access to external storage as Android.

Examples: UIFileSharingEnabled LSSupportsOpeningDocumentsInPlace

Several iOS tags were experimented with which did not result in equivalent plist settings or file write access.

Motivation Behind Feature

Documentation leads one to believe writing files to folders that will then be accessible in the iOS file browser ('Files' app) is a matter of choosing the correct cordova.file.* definition from the provided table. There is no mention of the XCode build options that must also be added. Managing these details fits within the scope of platform agnostic tooling. The requirement is a surprise and a troubleshooting time sink.

Ref: https://stackoverflow.com/questions/59825500/ionic-4-ios-file-access-with-ionic-native-file-ngx-cordova-plugin-file

Feature Description

Improve iOS documentation or improve plugin installation and implementation. Manage build options or document that they ought to be.

Alternatives or Workarounds

Manually adjust your framework's iOS build options or XCode's -info-plist to actually make the cordoval.file. choices work.

John867530nine avatar May 29 '20 00:05 John867530nine

Thank you so much! After adding these 2 setting to the x-info.plist file. Now I can see a my application name's folder and files wrote by cordova-file-plugin in iOS 12 built-in app Files!!!

/platforms/ios/x-Info.plist

	<key>UIFileSharingEnabled</key>
	<true/>
	<key>LSSupportsOpeningDocumentsInPlace</key>
	<true/>

write file testing script can be used in Safari dev console

window.resolveLocalFileSystemURL(
  cordova.file.documentsDirectory,
  function(fs) {
    console.log(
      `$ file system opened cordova.file.dataDirectory ${cordova.file.documentsDirectory} fs.name ${fs.name}`,
    );
    const fileName = `123-test-${Math.random().toString()[3]}.json`;
    console.log(`$ opening ${fileName}`);
    fs.getFile(fileName, { create: true, exclusive: false }, function(fileEntry) {
      console.log(`$ opened fileName ${fileName}`);
      console.log(`$ fileEntry.createWriter`, fileEntry.createWriter);
      fileEntry.createWriter(function(fileWriter) {
        console.log(`$ fileWriter`, fileWriter);
        fileWriter.fileName = fileName;
        fileWriter.onwriteend = function() {
          console.log('$  Successful file write... fileEntry.fullPath', fileEntry.fullPath);
          alert(fileEntry.fullPath);
        };

        fileWriter.onerror = function(e) {
          console.error('$ Failed file write: ' + e.toString());
        };

        fileWriter.write(new Blob(['{}'], { type: 'text/plain' }));
      });
    });
  },
  err => {
    console.error(`$ resolveLocalFileSystemURL err`, err);
  },
);

iPhone 6 iOS 12 "cordova": "^10.0.0" "cordova-ios": "^6.1.1" "cordova-plugin-file": "^6.0.2"

corresponding settings in XCode

Screenshot 2022-01-06 at 12 24 25 pm

JaosnHsieh avatar Jan 06 '22 04:01 JaosnHsieh

After three f'n years I finally discovered these keys; added them, and now my downloaded files can be accessed by users. After, I then found this thread. Its darn near 3 years old and STILL hasn't made its way into the documentation - in fact, its pretty much absent from any and all Cordova documentation. The guy who told me about it said the following:

Historically these plist values were used to expose an app's documents folder via iTunes (they pre-date the existence of the Files app on iOS). When Apple added the Files app then they used these values to also show your app's documents in files.

rolinger avatar Mar 07 '23 02:03 rolinger