Page 1 of 1
What handler is sent when app closed on an iOS device?
Posted: Thu Mar 12, 2015 9:41 am
by JustinW42
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?
Re: What handler is sent when app closed on an iOS device?
Posted: Thu Mar 12, 2015 5:57 pm
by jacque
Try "shutdown". If the app isn't specifically closed by the user though the message may not be sent.
Re: What handler is sent when app closed on an iOS device?
Posted: Fri Mar 13, 2015 2:17 am
by Simon
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).
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
Re: What handler is sent when app closed on an iOS device?
Posted: Fri Mar 13, 2015 5:07 am
by Thierry
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:
Regards,
Thierry
Re: What handler is sent when app closed on an iOS device?
Posted: Fri Mar 13, 2015 5:17 am
by Simon
Hi Thierry,
WOW!
Can you elaborate on your code a bit more?
Simon
Re: What handler is sent when app closed on an iOS device?
Posted: Fri Mar 13, 2015 6:43 am
by jacque
Thierry, is this part of your MIDI external?
Re: What handler is sent when app closed on an iOS device?
Posted: Fri Mar 13, 2015 7:25 am
by JustinW42
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.

Re: What handler is sent when app closed on an iOS device?
Posted: Fri Mar 13, 2015 7:32 am
by JustinW42
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!

Re: What handler is sent when app closed on an iOS device?
Posted: Sat Mar 14, 2015 6:59 pm
by Thierry
@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.
Regards,
Thierry
Re: What handler is sent when app closed on an iOS device?
Posted: Sun Mar 15, 2015 7:35 am
by JustinW42
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.
Re: What handler is sent when app closed on an iOS device?
Posted: Sun Mar 15, 2015 9:13 am
by Thierry
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