What handler is sent when app closed on an iOS device?
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
What handler is sent when app closed on an iOS device?
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?
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
Some things I do: http://www.katanadtg.com --- http://www.dtgprintsolutions.com
-
- 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?
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
HyperActive Software | http://www.hyperactivesw.com
-
- 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?
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.
Simon
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.
Ackk, we still have no way of detecting when the app is not in focus (background).would I need to specifically code the app to do the same thing when they send it to the background?
Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!
Re: What handler is sent when app closed on an iOS device?
Mmmm, here is some code in one of my stack: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).
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
Thierry
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!
-
- 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?
Hi Thierry,
WOW!
Can you elaborate on your code a bit more?
Simon
WOW!
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!
-
- 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?
Thierry, is this part of your MIDI external?
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
Re: What handler is sent when app closed on an iOS device?
Hmmm same results - nada. haha For some reason my app doesn't want to accept any sort of handlers when it closes.jacque wrote:Try "shutdown". If the app isn't specifically closed by the user though the message may not be sent.
-------------------------------------------------------------------------------------------------------------
Some things I do: http://www.katanadtg.com --- http://www.dtgprintsolutions.com
Some things I do: http://www.katanadtg.com --- http://www.dtgprintsolutions.com
Re: What handler is sent when app closed on an iOS device?
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!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.
However, I am very interested in understanding Thierry's code a little more.... It looks like it goes well beyond the standard handlers!
-------------------------------------------------------------------------------------------------------------
Some things I do: http://www.katanadtg.com --- http://www.dtgprintsolutions.com
Some things I do: http://www.katanadtg.com --- http://www.dtgprintsolutions.com
Re: What handler is sent when app closed on an iOS device?
@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
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
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!
Re: What handler is sent when app closed on an iOS device?
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
Some things I do: http://www.katanadtg.com --- http://www.dtgprintsolutions.com
Re: What handler is sent when app closed on an iOS device?
Great!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.
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.
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!