Splashstack and datastack for iPhone

Getting into LiveCode for iOS? Ask your questions here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4163
Joined: Sun Jan 07, 2007 9:12 pm

Splashstack and datastack for iPhone

Post by bn » Mon Jan 31, 2011 12:38 am

Hi all,

there was a long thread of using the Splash and Stack approach for the iPhone on this forum
http://forums.runrev.com/phpBB2/viewtop ... 3&start=45
As of Livecode version 4.5.3 it is possible to save stacks in the documents folder of the iPhone. This basically opens up the possibility to use one stack, the splash-screen stack to start the app and use the other stack as a working stack that can save its changes and is backed up by iTunes.

The stack I posted over there was a very rough proof of principle stack.

Here I would like to post a stack that shows how to do it in a little more refined way. Still basically a proof of principle.

There are some things to consider. The two stacks - Splash and Data are linked. You can not save directly into the documents folder of the iOS device but in the standalone application settings in Livecode for the Splash stack you can include a file.
standalone-application-settings.png
standalone-application-settings.png (55.94 KiB) Viewed 14197 times
This file, the stack Data.livecode is copied to the 'engine' folder of the application when it is build.
Now the Splash stack when starting on the iDevice looks for the Data stack in the documents folder, if not found it will copy the data stack to the documents folder and there the Data stack stays and can be modified and saved.
Whenever the Splash stack starts it will find the Data stack in the documents folder and use it, no more copying of the data stack from engine folder to documents folder.

This set-up is important to understand since when you change the data stack in Livecode and then use it in the Simulator or the actual device, the new Data stack will NOT be copied to the documents folder, only the Splash stack is replaced.
So this has an important consequence:

WHENEVER YOU CHANGE YOUR APP DELETE THE VERSION YOU PUT ON THE SIMULATOR OR THE IPHONE FIRST BEFORE TESTING THE NEW VERSION.

The rest should be pretty obvious and you can always read up on the pitfalls in the long thread cited above or ask here.

But be aware that this is not a shure fire recipe for app approval, the iOS is after all a touch operated OS and the user expects a certain interface and handling. Also you have to consider how you would want to change the logic of the data stack in case of an update/added functionality without wiping the users data, which are stored in the data stack.

Oh, when in the data stack and you have more than one card swipe to the right or swipe to the left to go from one card to the next.

Kind regards

Bernd
Attachments
splash and stack.zip
(41.52 KiB) Downloaded 513 times

Kangaroo SW
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 40
Joined: Sat Jan 15, 2011 10:57 am

Re: Splashstack and datastack for iPhone

Post by Kangaroo SW » Tue Feb 01, 2011 12:45 pm

Hello Bernd

:arrow: Phantastic Tutorial and Stack ! :D

Cheers
Rolf

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4163
Joined: Sun Jan 07, 2007 9:12 pm

Re: Splashstack and datastack for iPhone

Post by bn » Tue Feb 01, 2011 1:41 pm

Hi Rolf,

thank you.

I did not know that Kangaroos use Livecode and even iOS, maybe it is the touch interface that finally won them over. They prefer to scroll. :)

Wieders, Gierkes, Majors and Gaskins I know of, but Kangaroos is new to me. :wink:

The future of Livecode looks bright!

Kind regards

Bernd

sylvanr
Posts: 80
Joined: Wed Nov 24, 2010 10:38 am

Re: Splashstack and datastack for iPhone

Post by sylvanr » Wed Feb 02, 2011 12:46 am

Great, Bernd! These instructions will make it much easier for others. Thanks again for all your help!

I have trying to submit my little app to the Apple Store and created another topic regarding that process that seems a little daunting so far. I am in a "prepare for upload" state and I guess waiting to hear from Apple that I am "ready for upload."

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4163
Joined: Sun Jan 07, 2007 9:12 pm

Re: Splashstack and datastack for iPhone

Post by bn » Wed Feb 02, 2011 12:57 am

Hi Sylvan,

good to hear you are on your way. Please keep us posted how it goes.

Kind regards

Bernd

sylvanr
Posts: 80
Joined: Wed Nov 24, 2010 10:38 am

Re: Splashstack and datastack for iPhone

Post by sylvanr » Wed Feb 02, 2011 8:22 pm

Progressed to the "waiting for upload" state. I am using the Application Loader but keep getting errors. One error that took me quite a while to resolve and which, for others, should be documented in the iOS documentation is that you have to change the profile when saving as a standalone application before uploading. I spent hours on that one problem. I got the distribution certificate from Apple but it wasn't entirely clear in the LiveCode documentation what I was to do with the certificate. The LiveCode documentation for iOS just seems to take you through the process of adding the Team Provisioning certificate for testing the app on the iPhone but it doesn't mention that you then have to replace that certificate with the distribution certificate before uploading to the Apple Store. I eventually stumbled across this. When I decided that I might need to replace that provisioning certificate, it also took me a while to figure out HOW to replace it. I finally discovered that I needed to drag the new distribution certificate to the Xcode icon before the certificate would show up in the pop-up profiles menu. It actually took me a couple of days to get there! I think it would be helpful for others to have that simple little process added to the documentation to save people a lot of time and grief.

Now, I have reached another roadblock. When I try my upload now, using the applicatoin loader, I get an error that says "cssmerr_tp_not trusted" I have changed all my certificates to "trust always" and back to "default" but nothing seems to make a difference. I'm not sure what I'm doing wrong at this point. Somebody else on the forum said that they were using the ITunes Connect to upload their app rather than the Application Loader, but I can't see that option in iTunes Connect. Here is the actual error message:

"Application failed codesign verification. The signature was invalid, or it was not signed with an Apple submission certificate."
and

"Unable to extract codesigning entitlements from your application. Please make sure StudyCards.ap is a valid Mach executable that's properly codesigned."

This first app was just a simple little app to test out the whole process to see how everything worked. It has taken me a couple of months to get this far! Hopefully, the next one will go much smoother! :)

sylvanr
Posts: 80
Joined: Wed Nov 24, 2010 10:38 am

Re: Splashstack and datastack for iPhone

Post by sylvanr » Wed Feb 02, 2011 9:38 pm

Update- well, maybe persistence pays off?? After I had posted my last mssg here, I had sent a message to iTunes Connect regarding my problem with uploading the app. I'm not sure if they did something on their end or if I just stumbled into a solution again but I tried uploading one more time, and this time, after probably 30-40 tries, the iTunes store accepted the app and now it is just waiting for approval.

Danny
Posts: 106
Joined: Tue Nov 09, 2010 1:28 am

Re: Splashstack and datastack for iPhone

Post by Danny » Sat Feb 26, 2011 5:58 am

I guess i'm going to bring this topic back up in the ratings :D Two questions

1. I have made each card a standalone stack and included them in the first stack you see. So I have a "level select" standalone stack and a "Level" standalone stack etc. When I run it in the sim all the stacks work fine, switching them is no problem, but when I run it on my iPod I can't get it to change cards. I've tired "go stack Level Select" and "open stack Level Select" but none of it opens the card.

2. I need help with this whole saving thing. I got it to work in the simulator but I always had to press a button. When I changed it to "on shutDown" or "on closeStack" it didn't save it. Now I don't have too much in the way of code directed towards saving files in the Documents folder and the reason is that I saw that it worked in the simulator. When I did have code directed towards saving files in the Documents folder it didn't work. Help

I did use your sample program but I didn't really see how you were saving it in the scripts. But I did see that it was saving perfectly on my iPod.

Thanks,

Danny

John Allijn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 65
Joined: Sat Feb 26, 2011 10:02 am

Re: Splashstack and datastack for iPhone

Post by John Allijn » Sat Feb 26, 2011 10:14 am

Great, I've been searching for this a while!

About the splash-stack: How does the button work to go to the data-stack? I was expecting to find a <go to stack "data"> expression but couldn't find that. I'd like to replace the button with an image and jump to the data-stack 'on mouseup'

I love the ability to swipe in the data stack. I was looking for something like that in text-fields. Is it possible to make the text field in the data-stack respond to a swipe-up and swipe-down gesture so that when there is a lot of text in that field you can scroll it up and down (just like the ios/iphone addresbook for example?) I've tried that in numerous ways but can't get it to work :(

thanks!

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4163
Joined: Sun Jan 07, 2007 9:12 pm

Re: Splashstack and datastack for iPhone

Post by bn » Tue Mar 01, 2011 2:17 pm

Hi John,

you find the code in the red button "go data stack"

Code: Select all

on mouseUp
   if the environment is "mobile" then
      put (specialFolderPath("Documents") & "/data.livecode") into tPathToDatabase
      put (specialFolderPath("engine") & "/data.livecode") into tPathToStartLoc
      
      try
         if not (there is a file tPathToDatabase) then
            put url ("binfile:" & tPathToStartLoc) into temp
            put temp into url ("binfile:" & specialfolderpath("Documents") & "/data.livecode")
            wait 5 milliseconds with messages
         end if
      catch pErr
         put pErr into field 1
      end try
      try
         go stack tPathToDatabase
      catch pErr
         put pErr into field 1
      end try
   end if
end mouseUp
As for swiping the text field: do you want to swipe a locked text field or do you want to swipe a text field that is editable?

For swiping a locked text field have a look at
http://forums.runrev.com/phpBB2/viewtop ... =49&t=6876

if it is an editable field I would have to look into that. The tricky part would be to decide when to enter text and when to scroll.



@ Danny

the code for saving is in the stack script of the data stack:

Code: Select all

on shutDown
   save this stack
end shutDown
with this code there should not be a need to hit a 'save' button.

I dont understand exactly what you are doing
How many stacks do you have? Are those stacks substacks of another stack or are they individual stacks?

Which one is the Splash stack? The splash stack is not saveable since it is the app and you can not save changes to the app.

If they are data-stacks and you moved them to the Documents folder they should work. Please explain or even better upload a simple zipped version of your project that shows the problem.

Kind regards

Bernd

Danny
Posts: 106
Joined: Tue Nov 09, 2010 1:28 am

Re: Splashstack and datastack for iPhone

Post by Danny » Wed Mar 02, 2011 5:30 am

@ Danny

I dont understand exactly what you are doing
I think an example program would be best
How many stacks do you have?
27 so far
Are those stacks substacks of another stack or are they individual stacks?
They are all individual mainStacks
Which one is the Splash stack?
The MainMenu stack
The splash stack is not saveable since it is the app and you can not save changes to the app.
So I've found :lol:
Please explain or even better upload a simple zipped version of your project that shows the problem.
Look out below! I don't know if my app will be a big one (Although you never know :) so I kept it more basic but with the same principle.
Explanations are in the app.

Hopefully I hit on all your questions hehe but let me know if you have more.

Thanks for taking the time,

Danny

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4163
Joined: Sun Jan 07, 2007 9:12 pm

Re: Splashstack and datastack for iPhone

Post by bn » Wed Mar 02, 2011 12:06 pm

Hi Danny,

somehow your stack is not uploaded.

Your have to zip it, upload it a then "add the file" as an extra step.

Kind regards

Bernd

Danny
Posts: 106
Joined: Tue Nov 09, 2010 1:28 am

Re: Splashstack and datastack for iPhone

Post by Danny » Wed Mar 02, 2011 7:00 pm

Wow I can't believe I forgot that. Here it is
Attachments
Saving Stacks Help.zip
(5.63 KiB) Downloaded 404 times

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4163
Joined: Sun Jan 07, 2007 9:12 pm

Re: Splashstack and datastack for iPhone

Post by bn » Wed Mar 02, 2011 8:45 pm

Hi Danny,

the only thing I changed was in the "StartMenu" stack to block in the button

Code: Select all

Open stack "Level Menu"
. Everything else worked out of the box.
I reassigned the "level Menu" stack in Standalone Application Settings-> Copy Files.
Everything worked in the Simulator and the iPhone. (iPhone G3 iOS 4.2.1)
Stars were saved and everything. Repeatedly starting the App there where no problems to go to the Level Menu stack.

Did you delete the app from the iPhone before loading a new version to the iPhone?

I am wondering if you should not go for substacks instead of 27 stacks. You could make your leves all substacks of the Level Menu stack. That should make things easier, I guess. Start with just one or two substack and see how it goes.

You might try the stack you posted on your iPhone and see if it works if you block that one line of code in the button.

Kind regards

Bernd

Danny
Posts: 106
Joined: Tue Nov 09, 2010 1:28 am

Re: Splashstack and datastack for iPhone

Post by Danny » Wed Mar 02, 2011 10:32 pm

Hey Bernd,
It's getting better but I have two questions.
As you can see in the program I used the

Code: Select all

on shutDown
save this stack
end shutDown
code, but when I tried it in my game, on my iPod, it didn't save. I have a button that has the same code and when I press it I can quit, come back, and it saves the stack. I'm not sure why this is going on. Does shutDown run when I quit the game or another time.

Second. I was wondering why preOpenStack only works once on my iPod. Because as you might've seen in my app I have some code that says when you open the stack, add up those fields. Is there a way around this?

And I was looking and I do have the levels in substacks under the "Level Menu" stack. I always delete the app from the simulator and my iPod after I saw some of your posts.

Thanks,

Danny

Post Reply