App works on Simulator but not Device

Getting into LiveCode for iOS? Ask your questions here.

Moderators: Klaus, FourthWorld, heatherlaine, kevinmiller, robinmiller

Post Reply
DirkArnold
Posts: 15
Joined: Sat May 14, 2011 11:35 pm
Location: Sunny Tucson, AZ

App works on Simulator but not Device

Post by DirkArnold » Thu Mar 02, 2017 2:03 am

Hello. I have an app that uses external mp3 and png files for its content. I have set the defaultFolder to specialFolderPath("resources"). Everything is fine in IDE, macOS executable, and iOS simulator. On an actual iOS device, however, none of the graphics or sounds appear. I get some startup data from a text file with

Code: Select all

put URL "File:score.txt" into gScore
and that is loading because I put in an

Code: Select all

answer gScore
to test it. I have looked inside the "package" and the files are there in their relative folders.

To load the graphics I typically use something along the lines of

Code: Select all

set the filename of image ("image" & y) to the defaultFolder & "/chapter" & y & "/images/" & fileNameOfTheImage
and I'm using similar path constructions for the audio files. (I have tried it with and without "the defaultFolder" in front.) I'm guessing iOS is pickier about how paths are constructed since only my simple one seems to work, but I haven't stumbled onto the magic syntax.

Or maybe I'm missing the subtleties of specialFolderPath.

Any thoughts?

Thanks! --Dirk

LiveCode_Panos
Posts: 306
Joined: Fri Feb 06, 2015 4:03 pm

Re: App works on Simulator but not Device

Post by LiveCode_Panos » Thu Mar 02, 2017 9:56 am

Hi Dirk,

Does this work:

Code: Select all

set the filename of image ("image" & y) to specialFolderPath("resources") & "/chapter" & y & "/images/" & fileNameOfTheImage
?

Best,
Panos
--

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

Re: App works on Simulator but not Device

Post by Klaus » Thu Mar 02, 2017 11:53 am

And if that does not work, try this:

Code: Select all

set the filename of image ("image" & y) to (specialFolderPath("resources") & "/chapter" & y & "/images/" & fileNameOfTheImage)
8)

DirkArnold
Posts: 15
Joined: Sat May 14, 2011 11:35 pm
Location: Sunny Tucson, AZ

Re: App works on Simulator but not Device

Post by DirkArnold » Sat Mar 04, 2017 9:15 pm

Thanks Panos and Klaus. Those didn't work but I think it's because I missed the actual problem:

As I mentioned above, I'm using "put URL" to get info out of text files. The one that's at the root of the specialFolderPath seems to work, as I said, but now I see that if I try to build a path...

Code: Select all

put ("file:chapter" & y & "/intro.txt") into theURL
put URL theURL into gChapterInfo
... "answer gChapterInfo" comes up blank on a device. How do I build a path that works with put URL? (Putting a slash after file: and in front of chapter breaks what works.)

Thanks again.

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

Re: App works on Simulator but not Device

Post by Klaus » Sun Mar 05, 2017 2:17 am

Hi Dirk,

first try this:

Code: Select all

...
put ("file:chapter" & y & "/intro.txt") into theURL
put URL theURL into gChapterInfo
answer the result
## the result will be empty on success or give a hint on what might go wrong
...
And then mayve build an absolute path instead of relying on the defaultfolder:

Code: Select all

...
put ("file:" & specialfolderpath("resources") & "/chapter" & y & "/intro.txt") into theURL
put URL theURL into gChapterInfo
answer the result
...
Best

Klaus

DirkArnold
Posts: 15
Joined: Sat May 14, 2011 11:35 pm
Location: Sunny Tucson, AZ

Re: App works on Simulator but not Device

Post by DirkArnold » Sun Mar 05, 2017 8:03 pm

Learning all kinds of things but still getting nowhere.
Put URL is apparently case sensitive.
Put URL apparently requires quotes around the URL, which makes it difficult to build a path from variables or hardcode specialFolderPath("resources") into a path.
I searched the forum for tips on escaping quotes but nothing seemed to apply to this situation. How does one do it?

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

Re: App works on Simulator but not Device

Post by Klaus » Sun Mar 05, 2017 8:55 pm

Sorry, do not understand what your poblems are? :shock:
Quotes neccessary? Case sensitive?
No capisce.

DirkArnold
Posts: 15
Joined: Sat May 14, 2011 11:35 pm
Location: Sunny Tucson, AZ

Re: App works on Simulator but not Device

Post by DirkArnold » Sun Mar 05, 2017 10:32 pm

Hi Klaus.
While experimenting I discovered that my filename had an initial cap but my code was lowercase. Answer the result gives me "Cannot open file" unless the filename and code match exactly.

Also, if I hardcode

Code: Select all

put URL "file:score.txt" into gScore
it works fine. But if I put the URL into a variable (theURL in our previous conversation) the result is "Cannot open file." It seems to me that I need to put quotes around theURL, or include surrounding quotes in the variable itself, but I can't figure out how.

I hope that's a little clearer. --Dirk

PS: To reiterate, these problems only appear on an actual device. IDE, desktop, iOS simulator all work fine.

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

Re: App works on Simulator but not Device

Post by Klaus » Sun Mar 05, 2017 11:24 pm

Hi Dirk,
DirkArnold wrote:Hi Klaus.
While experimenting I discovered that my filename had an initial cap but my code was lowercase. Answer the result gives me "Cannot open file" unless the filename and code match exactly.
ah, I see, and are really not surprised! :D
DirkArnold wrote:Also, if I hardcode

Code: Select all

put URL "file:score.txt" into gScore
it works fine. But if I put the URL into a variable (theURL in our previous conversation) the result is "Cannot open file." It seems to me that I need to put quotes around theURL, or include surrounding quotes in the variable itself, but I can't figure out how.
Hm, I do this all the time so please doublecheck the URL with an Answer dialog and/or an IF...END IF clause:

Code: Select all

...
put specialfolderpath("resources") & "/chapter" & y & "/intro.txt" into tURL
## Check the path first:
answer tURL

## Now check for existence of that file. 
## If you see the diakog, the path is not correct or the file really not present:
if there is NOT a file tURL then
  answer "No such file:" && tURL
  exit to top
end if
put url("file:" & tURL) into tWhatever
...
Best

Klaus

DirkArnold
Posts: 15
Joined: Sat May 14, 2011 11:35 pm
Location: Sunny Tucson, AZ

Re: App works on Simulator but not Device

Post by DirkArnold » Thu Mar 09, 2017 12:46 am

Hi Klaus. I guess I need to know what the correct path looks like. This *seems* ok but using your suggested code the answer is "no such file: /var/containers/Bundle/Application/bunchanumbers/MyApp.app/chapter1/intro.txt"

Is that the right place? On the simulator the path is the same from "containers/..." and the file loads, which makes me think so.

Thanks again! --Dirk

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

Re: App works on Simulator but not Device

Post by Klaus » Thu Mar 09, 2017 1:09 pm

Hi Dirk,
DirkArnold wrote:Hi Klaus. I guess I need to know what the correct path looks like.
since LC provides several specialfolderpath codes, I trust them to be correct!
This means you "only" need to know the correct path of the part that comes after these codes = YOUR stuff :D
DirkArnold wrote:This *seems* ok but using your suggested code the answer is "no such file: /var/containers/Bundle/Application/bunchanumbers/MyApp.app/chapter1/intro.txt"
Is that the right place? On the simulator the path is the same from "containers/..." and the file loads, which makes me think so.
Sorry, I have no idea, since I do not develop for mobile nor do I own any mobile device at all, not even a cellphone.
Yes, that's me! :D


Best

Klaus

DirkArnold
Posts: 15
Joined: Sat May 14, 2011 11:35 pm
Location: Sunny Tucson, AZ

Re: App works on Simulator but not Device

Post by DirkArnold » Sat Mar 11, 2017 6:38 am

I should pay more attention to myself, because the problem was indeed case-sensitivity as I suspected a few days ago. I had fixed a filename but neglected to notice a capitalized folder name and continued to bash my head against the wall needlessly. I fixed up my folder names and voila! Thanks for persisting until I believed that the problem was my "stuff" and not my code. :oops:

Thanks again, Klaus!

Post Reply

Return to “iOS Deployment”