How to delete settings json file from within app, particularly from iOS?

3516
1
09-07-2015 05:00 PM
PaulHaakma
Regular Contributor

Hi all,

Does anyone know how to delete the settings json from within the app while it is running, in particular on iOS? This file is stored at the path identified by: app.settings.path but the following code won't delete it:

 

function deleteAllSettingFiles(){

            console.log("TRYING TO DELETE THE SETTINGS FILE....")   //gets to here fine

            var filesList,  file, index, success, report

            filesList = settingsFolder.fileNames("*", false)

            for ( index in filesList){

                file = filesList[index]

                console.log("going through all the settings files... ", file)  //never gets this far...

                if (settingsFolder.fileExists(file)){

                    success = settingsFolder.removeFile(file);

                    report = file + " deleted? " + success

                    console.log(report)                

                }          }       }

I assume it is either because the file is locked since the app is using it, or the app doesn't have permissions to delete it. In Windows you can manually delete this file outside of the app, on Android you can 'clear the cache' of an app, but on iOS there is no OS method that I'm aware of that will clear this file except for completed uninstalling this file altogether.

The other alternative is to stop using the settings file, and instead implement my own settings file in a location that I control, but it seems a bit counterintuitive to having the app.settings file.

Any ideas?

Cheers,

-Paul

0 Kudos
1 Reply
ShobanaSuresh
Esri Contributor

Hi Paul,

app.settings.path returns the absolute path to the settings json file. 

e.g. By default app.settings.path returns /Users/username/ArcGIS/AppStudio/Settings/App_ItemID.json on Mac OS X

What is the path assigned to settingsFolder in the code above?

Below code works on iOS both in Player and stand alone app

````

Component.onCompleted: {

    app.settings.setValue(“textColor”, “blue”)

}

FileFolder {

   id: settingsFolder

   path: AppFramework.fileInfo(app.settings.path).path

}

Button {

   text: "Delete"

   onClicked: {

       console.log(settingsFolder.fileExists(app.settings.path)); // Prints true

       settingsFolder.removeFile(app.settings.path);

       console.log(settingsFolder.fileExists(app.settings.path)); // Prints false

}

````

Thanks

Shobana

0 Kudos