Copy Files in Standalone settings

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: Klaus, FourthWorld, heatherlaine, robinmiller, kevinmiller

Post Reply
trags3
Posts: 295
Joined: Wed Apr 09, 2014 1:58 am
Location: Las Vegas, NV

Copy Files in Standalone settings

Post by trags3 » Sun Jun 16, 2019 2:51 am

I have an issue that I'm pretty sure is caused by an external file not being loaded when I save as a Standalone Application.

I have a text file located on my MacBook Air running Mac OS 10.14.5 in the Documents folder.
In the Copy Files box in the Standalone Settings, I select this file to be copied in the build.

Everything works swimmingly on the mac but when I load it onto my iPhone 8+ iOS 12.3.2 the text file is either not accessible or not there.

I put a statement in the file to show the number of lines in the file:

set the defaultFolder to (specialFolderPath("documents") & slash)
put URL("file:" & (specialFolderPath(documents") & "/Script.txt")) into tfile
Put the number of lines of tfile into howmany
answer howmany

On the Mac I get the answer 366
On the iPhone the answer is 0

I think this is the first app I have written that needed a file that I needed to copy when building the app.

Is something wrong with the way I am copying the file to the iPhone?

Thanks

Tom

SparkOut
Posts: 1950
Joined: Sun Sep 23, 2007 4:58 pm

Re: Copy Files in Standalone settings

Post by SparkOut » Sun Jun 16, 2019 6:29 am

When you add files in the standalone builder, they will be bundled on the mobile device in the specialFolderPath ("resources") location. This is not a writeable location. If you need to save edits to the text file, you must copy it to the specialFolderPath ("documents") folder. (First check if it has previously been copied, or it will be overwritten with the same version that got bundled with the standalone. )
specialFolderPath ("documents") is a sandboxed folder accessible and writeable by your app, but not visible to other apps without root.
There is also specialFolderPath("external documents") if you need to make a file globally accessible.

Note the path is case sensitive and should be a lower case D.

trags3
Posts: 295
Joined: Wed Apr 09, 2014 1:58 am
Location: Las Vegas, NV

Re: Copy Files in Standalone settings

Post by trags3 » Sun Jun 16, 2019 1:35 pm

Thank You!
All is well 8)

Klaus
Posts: 11012
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Copy Files in Standalone settings

Post by Klaus » Sun Jun 16, 2019 2:14 pm

And no need to "set the defaultfolder" if you provide an ABSOLUTE path:

Code: Select all

...
## set the defaultFolder to (specialFolderPath("documents") & slash)
put URL("file:" & (specialFolderPath(documents") & "/Script.txt")) into tfile
...

Post Reply

Return to “Getting Started with LiveCode - Experienced Developers”