Page 1 of 1

Saving data on mobile

Posted: Wed Mar 17, 2021 9:39 pm
by glenn9
On deploying an app to mobile, I provide its data by including a data text file through 'Copy Files' in the standalone settings.

temp.png

I then import the data into the app using the following code:

Code: Select all

...
on openstack
set the defaultfolder to specialfolderpath("resources")
put url ("binfile:ArrayData.txt") into theEncodedArray
put arrayDecode(theEncodedArray) into vText

put specialfolderpath("documents") & "/" & "ArrayData.txt" into tMyPath
put arrayEncode(vText) into url ("binfile:" & tMyPath)
...
This works fine on mobile, and if the user then subsequently adds data, this is then saved as expected in specialfolderpath("documents").

However, if the app is closed and then restarted, the previously saved data is then, I think, overwritten by the original file from the specialfolderpath("resources").

I guess what I am trying to achieve is that on app installation on the mobile device, the data from specialfolderpath("resources") is transferred once to the app and then if the app is closed and opened again, it then only takes its data from specialfolderpath("documents").

I'm not sure how to achieve this, grateful for any help or suggestions etc.

Many thanks,

Glenn

Re: Saving data on mobile

Posted: Wed Mar 17, 2021 9:50 pm
by Klaus
Hi Glenn,

just check if the file is already in DOCUMENTS!

Code: Select all

on openstack
   put specialfolderpath("documents") & "/" & "ArrayData.txt" into tUserData
   put specialfolderpath("resources") & "/" & "ArrayData.txt" into tResData
   
   ## No file yet, so copy the resource file to folder DOCUMENTS
   if there is NOT a file tUserData then
      put url ("binfile:" & tResData) into url("binfile:" & tUserData)
   end if
   
   ## Now load the data from the DOCS folder
   put url ("binfile:" & tUserData) into theEncodedArray   
   ...
Best

Klaus

Re: Saving data on mobile

Posted: Wed Mar 17, 2021 9:52 pm
by stam
Hi Glenn,
it probably is as simple as checking if specialfolderpath("documents") & "/" & "ArrayData.txt" exists

and only doing put arrayEncode(vText) into url ("binfile:" & tMyPath) if it doesn't?


--------------------------------
EDIT
--------------------------------
dammit!
outklaussed again lol

Re: Saving data on mobile

Posted: Wed Mar 17, 2021 9:57 pm
by glenn9
Klaus, Stam,

brilliant, thank you, that's solved it!

Another learning point...!

Regards,

Glenn