What handler is sent when app closed on an iOS device?

Getting into LiveCode for iOS? Ask your questions here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
JustinW42
Posts: 52
Joined: Sun Nov 30, 2014 7:22 am
Location: Upland, CA
Contact:

What handler is sent when app closed on an iOS device?

Post by JustinW42 » Thu Mar 12, 2015 9:41 am

I have tried the closeStack handler, as well as closeStackRequest... Neither of them seem to be working as expected once I deploy to an iOS device. I am basically trying to save the current state of the application when the user exits, by saving a .dat file in the "documents" folder path on the device. Everything works fine on desktop, but not on an iOS device..... For the record, if i copy the code (which handles the saving information to a file) and place it in a button on the Menu of the app, it works great! When I load the app after saving the data it automatically logs me in and does what it needs to do in the openStack handler - no problems there.

For some reason, I simply can't manage to make it work automatically in either of the handlers I listed above.... For testing, I added a few answer commands to the handlers and they don't show up when I close the app, but I am not even sure they would execute anyways once the user closes the app on their device (I am unclear as to how iOS devices handle answer statements after the user has told the phone to close the app - I have never seen a popup before, when closing any other apps on my device).

I've tried the code as presented by Klaus in the following thread: http://forums.livecode.com/viewtopic.ph ... 54#p114942

Again, nothing happens when I close the mobile app on an iOS device. One difference though - I put my code directly in the handler, whereas he used a command to call the code...... Is there some LiveCode rule that requires you to place the code outside of the actual handler?

One more thing - once I figure out why it isn't working when the app is closed, would I need to specifically code the app to do the same thing when they send it to the background? Or is the same handler request sent for both interactions?
-------------------------------------------------------------------------------------------------------------
Some things I do: http://www.katanadtg.com --- http://www.dtgprintsolutions.com

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7266
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: What handler is sent when app closed on an iOS device?

Post by jacque » Thu Mar 12, 2015 5:57 pm

Try "shutdown". If the app isn't specifically closed by the user though the message may not be sent.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am
Location: Palo Alto

Re: What handler is sent when app closed on an iOS device?

Post by Simon » Fri Mar 13, 2015 2:17 am

Hi Justin,
When you hit the "home" button on iOS the app is not actually shutting down but going into the background. When the memory is needed then the app is shut down but I believe it is a "brutal shut down" (like pulling the power) and the stack does not get to finish (OK I'm not positive on that point as I've never tested it). :roll:

When I make these preference type files for mobile I write to the file when the change is made. You could put it into a "Save" button. People expect to use a save after entering data. Yes this does mean you might have to write the file multiple times but it's quick and easy.
If it's in a field just stick all the writing code into an "on closeField" handler.
would I need to specifically code the app to do the same thing when they send it to the background?
Ackk, we still have no way of detecting when the app is not in focus (background).

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

Thierry
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 875
Joined: Wed Nov 22, 2006 3:42 pm

Re: What handler is sent when app closed on an iOS device?

Post by Thierry » Fri Mar 13, 2015 5:07 am

When you hit the "home" button on iOS the app is going into the background. When the memory is needed then the app is shut down but I believe it is a "brutal shut down" (like pulling the power) and the stack does not get to finish (OK I'm not positive on that point as I've never tested it)
Ackk, we still have no way of detecting when the app is not in focus (background).
Mmmm, here is some code in one of my stack:

Code: Select all

   -- user press home or power button
   p "Get notification changeOfApplicationState: " & flag
   if flag is "LD" then
      put true into isInLockDevice
   else if flag is "BG" then
      put true into isInBackground
   else if flag is "FG" then
      put false into isInLockDevice
      put false into isInBackground
   end if
and a screenshot of a Live Debug Session of my iPad with Xcode 6:
sunnYscreenshot Xcode6.png
Regards,

Thierry
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am
Location: Palo Alto

Re: What handler is sent when app closed on an iOS device?

Post by Simon » Fri Mar 13, 2015 5:17 am

Hi Thierry,
WOW! :shock:
Can you elaborate on your code a bit more?

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7266
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: What handler is sent when app closed on an iOS device?

Post by jacque » Fri Mar 13, 2015 6:43 am

Thierry, is this part of your MIDI external?
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

JustinW42
Posts: 52
Joined: Sun Nov 30, 2014 7:22 am
Location: Upland, CA
Contact:

Re: What handler is sent when app closed on an iOS device?

Post by JustinW42 » Fri Mar 13, 2015 7:25 am

jacque wrote:Try "shutdown". If the app isn't specifically closed by the user though the message may not be sent.
Hmmm same results - nada. haha For some reason my app doesn't want to accept any sort of handlers when it closes. :shock:
-------------------------------------------------------------------------------------------------------------
Some things I do: http://www.katanadtg.com --- http://www.dtgprintsolutions.com

JustinW42
Posts: 52
Joined: Sun Nov 30, 2014 7:22 am
Location: Upland, CA
Contact:

Re: What handler is sent when app closed on an iOS device?

Post by JustinW42 » Fri Mar 13, 2015 7:32 am

Simon wrote:When I make these preference type files for mobile I write to the file when the change is made. You could put it into a "Save" button. People expect to use a save after entering data. Yes this does mean you might have to write the file multiple times but it's quick and easy.
If it's in a field just stick all the writing code into an "on closeField" handler.
That was my backup plan.... There are only 4 instances in which I would need to edit the local settings file (when a user logs in or out of their account, and when a user logs in or out of a specific group) so it isn't a big deal, logistically - my concern was more about conserving resources as much as possible and trying to reduce the number of times my app has to access outside data. I guess if it doesn't take long to manipulate the file then I shouldn't waste days of my life trying to resolve it the way I had originally intended. lol Thanks for the tip!

However, I am very interested in understanding Thierry's code a little more.... It looks like it goes well beyond the standard handlers! 8)
-------------------------------------------------------------------------------------------------------------
Some things I do: http://www.katanadtg.com --- http://www.dtgprintsolutions.com

Thierry
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 875
Joined: Wed Nov 22, 2006 3:42 pm

Re: What handler is sent when app closed on an iOS device?

Post by Thierry » Sat Mar 14, 2015 6:59 pm

@simon, @justin:
Well, not much to say about the code.
Just has to define a handler which will receive notifications during
iOS states transition. A couple of customers are happy with it but,
as it has been said already,
there is, as far as I know, no official support from LiveCode Ltd.

@jacque:
No, it's not part of sunnYmidi (still MacOS only), but from another one which plays
a midi file on iOS. (see screenshot).
I had to code those Application State transitions, as on iOS it's mandatory
to set that Audio is working in the background.
sunnYmidiPlayer.png
Regards,

Thierry
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!

JustinW42
Posts: 52
Joined: Sun Nov 30, 2014 7:22 am
Location: Upland, CA
Contact:

Re: What handler is sent when app closed on an iOS device?

Post by JustinW42 » Sun Mar 15, 2015 7:35 am

Thanks Thierry! I am gonna take a closer look at it and see if it is something I can adapt for my purposes. Very cool.
-------------------------------------------------------------------------------------------------------------
Some things I do: http://www.katanadtg.com --- http://www.dtgprintsolutions.com

Thierry
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 875
Joined: Wed Nov 22, 2006 3:42 pm

Re: What handler is sent when app closed on an iOS device?

Post by Thierry » Sun Mar 15, 2015 9:13 am

JustinW42 wrote:Thanks Thierry!
I am gonna take a closer look at it and see if it is something I can adapt for my purposes.
Very cool.
Great!

Feel free to contact me off-list if you need such an external.

Have a nice sunday,

Thierry
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!

Post Reply

Return to “iOS Deployment”