Storing data locally

Getting into LiveCode for iOS? Ask your questions here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
Tomjr
Posts: 3
Joined: Mon Dec 12, 2011 7:43 pm

Storing data locally

Post by Tomjr » Mon Dec 12, 2011 7:49 pm

Hello all,

How would I go about storing data locally onto an iOS device so that it is always there even when someone closes and reopens the app?

Thanks :)

Jellicle
Posts: 453
Joined: Thu Feb 24, 2011 11:07 am

Re: Storing data locally

Post by Jellicle » Mon Dec 12, 2011 10:37 pm

Save it into the app's Documents folder. Here's some code showing how to write a text file to that folder:

Code: Select all

on writeTextFile fileTowrite,dataTowrite
   set the defaultFolder to specialFolderPath("Documents")
   put dataTowrite into URL (("file:"&fileTowrite&".txt"))
end writeTextFile
You pass the file name and data to the command. So

Code: Select all

 writeTextFile "preferences","1,0,3,4,5"
would write "1,0,3,4,5" to a file named preferences.txt into the Documents folder.

Gerry
14" MacBook Pro
Former LiveCode developer.
Now recovering.

Tomjr
Posts: 3
Joined: Mon Dec 12, 2011 7:43 pm

Re: Storing data locally

Post by Tomjr » Mon Dec 12, 2011 10:44 pm

Thanks! And how would I read that data?

Jellicle
Posts: 453
Joined: Thu Feb 24, 2011 11:07 am

Re: Storing data locally

Post by Jellicle » Mon Dec 12, 2011 11:26 pm

Tomjr wrote:Thanks! And how would I read that data?

Code: Select all

 function readFromFile whatFile
   set the defaultFolder to specialFolderPath("Documents")
   return URL (("file:"&whatFile&".txt"))
end readFromFile 
So you can do:

Code: Select all

put readFromFile("preferences") into field "PreferencesField"
Gerry
14" MacBook Pro
Former LiveCode developer.
Now recovering.

Tomjr
Posts: 3
Joined: Mon Dec 12, 2011 7:43 pm

Re: Storing data locally

Post by Tomjr » Tue Dec 13, 2011 12:24 am

Thank you very much! :)

FireWorx
Posts: 362
Joined: Wed Sep 07, 2011 9:39 pm

Re: Storing data locally

Post by FireWorx » Fri Dec 30, 2011 6:38 pm

Hi, I was checking the ability to update my PDF maps via iTunes by dropping the updates into the appropriate folder located in the documents folder. I have several folders with say 50 PDF's each in them.

All is good BUT.... I noticed that my Preferences folder which contains a text file that I write to and write from is also open for viewing and editing. This is not a good thing because for one thing I use the prefs file to do some time calculations that allow the users to try the program for 6 weeks. Altering this file and re inserting it could give the user an unlimited free trial.

SO... The question is. Are there other IOS folders that allow the contents to be changed via script but are not subject to file sharing if it is turned on in the standalone settings? Or are there settings that can be employed on certain folders within the documents folder that lock them or that can make files or folders invisible or locked?

What might be the best method to have several folders that can be edited and shared as well as having others that can be edited but are not shared?
Dave

gpb01
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 281
Joined: Sat Jun 04, 2011 5:41 pm

Re: Storing data locally

Post by gpb01 » Fri Dec 30, 2011 7:16 pm

FireWorx wrote: ...
SO... The question is. Are there other IOS folders that allow the contents to be changed via script but are not subject to file sharing if it is turned on in the standalone settings?
...
Use the "Library" folder ... he is backuped but is not accessible via iTunes Document Sharing :wink:

Guglielmo

FireWorx
Posts: 362
Joined: Wed Sep 07, 2011 9:39 pm

Re: Storing data locally

Post by FireWorx » Fri Dec 30, 2011 8:07 pm

Thanks I will givie that a try !

Post Reply