How to make a mobile app stay alive in the background?

Graham Samuel livfoss at
Mon Apr 27 07:12:55 EDT 2020

Panos, thanks for that info. The truth is my particular app has proved such a challenge for me in so many different ways that it may never reach its intended user population - but on the off-chance that I do finish it, then I think I may have to get involved with the Apple App Store, if only to use TestFlight to get it out to quite a lot of people. So maybe my announcement at that point will be that if your phone only runs earlier versions of iOS, sorry it won’t work unless you are willing to use it without ever letting the app go into the background - something very awkward in practice if you’re walking for an hour, which is what first use is all about. Can you say what is the lowest version of iOS is that would allow background working without a problem? Right now in my other test device I’m running iOS 13, which must be OK, but are there others, 11.x and 12. x that would be OK?

Having asked that, please note that ‘running in the background’ seems to mean different things to different people, but to me it means continuing to receive sensor data while in the background, since as far as I know, such data would be unrecoverable if not collected in real time. A good example would be working out how far a person has walked. This can only be done by accumulating increments of change of location (via GPS) without any serious gaps, so data acquisition has to be continuous. There are lots of other examples, specially if we’re allowing Bluetooth connected sensors.

Just for completeness I should say that I have asked LC Support to explain commands like mergBgTask, as the available documentation does not give examples etc. and really does not help the newbie in this area.


> On 27 Apr 2020, at 10:24, panagiotis merakos via use-livecode <use-livecode at> wrote:
> Hello all,
> Just to add to the discussion that one of Graham's phones runs iOS 10.x, so
> in this case, if you need your app to continue running in the background,
> you do need to build it with 9.5.1 and check the "enable background
> execution" checkbox in the iOS settings. However, you will not be able to
> submit this build to the AppStore, as Apple no longer accepts applications
> that have this key that is added to the plist if you check "Enable
> Background execution". Devices running newer iOS versions will   allow apps
> running in the background anyway, so you do not need this key in the plist
> - and this is why this key (i.e. the checkbox) was removed in LC 9.6 DP-3.
> So, to conclude, given that you are not interested in submitting the app to
> the AppStore, I believe you can include this key to the plist (i.e. check
> "Enable Background Execution" checkbox), so your app will continue running
> in the background in both old and new iOS devices.
> Kind regards,
> Panos
> --
> On Mon, 27 Apr 2020 at 10:42, Graham Samuel via use-livecode <
> use-livecode at> wrote:
>> Thanks Jacque and Mark - very interesting! Your messages told me stuff I
>> did not know. mergBgTask looks scary and somewhat unsure of itself, but
>> i’ll try.
>> What is happening to me is that the app is suspended and effectively
>> stopped when it goes into the background. From this state it can only be
>> relaunched, showing the splash screen which I had to provide to iOS (this
>> is not a card in my stack, just a PNG file insisted on by Apple), so the
>> user does not perceive the app to be resuming, but rather restarting. I
>> want them to see the screen they last saw when the app was in the
>> foreground. Plenty of apps do this - Strava, FitDigits, etc. More
>> importantly they do continue to actually run in the background, so that
>> there are for example no gaps in the sensor records they are displaying,
>> either via Bluetooth (Heart Rate Monitors for example) or direct via the OS
>> (GPS information). I need that facility or my app is dead in the water. I
>> don’t have trouble restoring the  app’s status on a restart, as I keep
>> updating the status and storing it in the cache area of my app - but that
>> doesn’t help with the continuous-monitoring-in-the-background requirement.
>> BTW, Jacque you said
>>> You are probably running an older version of LC since that checkbox has
>> been removed recently.
>> Perhaps in the latest DP, but it’s there in the latest official version,
>> 9.5.1, at least in Indy, which I use.
>> Will keep trying.
>> Graham
>>> On 27 Apr 2020, at 08:48, Mark Waddingham via use-livecode <
>> use-livecode at> wrote:
>>> On 2020-04-27 07:25, J. Landman Gay via use-livecode wrote:
>>>> On 4/26/20 4:43 PM, Graham Samuel via use-livecode wrote:
>>>>> I notice in the Standalone Settings for iOS in LC 9.5.1, a button
>> ‘Background Execution’. If I click it, I get a warning that I don’t really
>> understand which suggests that LC doesn’t officially support the feature.
>> I’m not even sure if this feature is what I need.
>>>> Basically you have to save the user state repeatedly whenever anything
>>>> significant changes, in case the app goes dormant.
>>> You actually need to do this regardless of having suspend/resume
>> messages as there's no guarantee that (1) you will get them and (2) you
>> will be able to execute them long enough to save all current state.
>>> Both mergBgTask and mergNotify provide features to enable managing the
>> background task feature of iOS, and the suspend/resume notifications though.
>>> Warmest Regards
>>> Mark.
>>> --
>>> Mark Waddingham ~ mark at ~
>>> LiveCode: Everyone can create apps
>>> _______________________________________________
>>> use-livecode mailing list
>>> use-livecode at
>>> Please visit this url to subscribe, unsubscribe and manage your
>> subscription preferences:
>> _______________________________________________
>> use-livecode mailing list
>> use-livecode at
>> Please visit this url to subscribe, unsubscribe and manage your
>> subscription preferences:
> _______________________________________________
> use-livecode mailing list
> use-livecode at
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:

More information about the use-livecode mailing list