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

Graham Samuel livfoss at mac.com
Mon Apr 27 11:34:42 EDT 2020


Panos, as usual, this is terrific information! I am applying your advice immediately.

Not to start an argument, the statistics you quote don’t accord with my personal experience. Almost everyone I know who owns Apple kit has at least one phone or iPad that can’t be upgraded to the latest OS version - and these devices still work well. In our house for example there are three iPhones, only one of which can run 13.x; two iPads, one newish one and another which is back at iOS 9 I think (still works for email and browsing, at any rate). However, to be practical I will  do as you suggest with my own app.

Thanks for your continued interest in these issues.

Graham

> On 27 Apr 2020, at 14:11, panagiotis merakos via use-livecode <use-livecode at lists.runrev.com> wrote:
> 
> Hello Graham,
> 
> I could not find any *official* source from Apple, as their docs are
> scattered around and it is not easy to determine always if a document is
> out of date, but from what I understand iOS apps are running in the
> background by default since iOS 12+. Given how quickly people are moving
> (or forced to move) to using the latest iOS versions, I would not worry if
> my app (in the AppStore) only covered iOS 12+:
> 
> iOS version stats: (from https://david-smith.org/iosversionstats/)
> 
> 13.X --> 92.5%
> 12.X --> 5.1%
> 11.X --> 0.7%
> 10.X --> 0.7%
> 9.X --> 1.0%
> 
> For your use case, I think this should work:
> 
> - Use LC 9.5.1 and check "Enable Background Execution" and "Location
> Updates" in the background modes in the iOS settings. This should allow
> your app to receive the "locationChanged" msg even when in background. Then
> use an ad-hoc distribution profile to sign your app and deliver it to
> specific devices (including pre-ios12) to get some feedback
> 
> - When you are ready for publishing the app to the AppStore, just rebuild
> it with LC 9.6, using an AppStore distribution profile, and upload it to
> the AppStore. You will be able to deliver it to some beta testers via
> TestFlight at this point (running iOS 12+)
> 
> Hope this helps.
> 
> Kind regards,
> Panos
> --
> 
> On Mon, 27 Apr 2020 at 14:14, Graham Samuel via use-livecode <
> use-livecode at lists.runrev.com> wrote:
> 
>> 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.
>> 
>> Graham
>> 
>>> On 27 Apr 2020, at 10:24, panagiotis merakos via use-livecode <
>> use-livecode at lists.runrev.com> 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 lists.runrev.com> 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 lists.runrev.com> 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.com ~ http://www.livecode.com/
>>>>> LiveCode: Everyone can create apps
>>>>> 
>>>>> _______________________________________________
>>>>> use-livecode mailing list
>>>>> use-livecode at lists.runrev.com
>>>>> Please visit this url to subscribe, unsubscribe and manage your
>>>> subscription preferences:
>>>>> http://lists.runrev.com/mailman/listinfo/use-livecode
>>>> 
>>>> 
>>>> _______________________________________________
>>>> use-livecode mailing list
>>>> use-livecode at lists.runrev.com
>>>> Please visit this url to subscribe, unsubscribe and manage your
>>>> subscription preferences:
>>>> http://lists.runrev.com/mailman/listinfo/use-livecode
>>>> 
>>> _______________________________________________
>>> use-livecode mailing list
>>> use-livecode at lists.runrev.com
>>> Please visit this url to subscribe, unsubscribe and manage your
>> subscription preferences:
>>> http://lists.runrev.com/mailman/listinfo/use-livecode
>> 
>> 
>> _______________________________________________
>> use-livecode mailing list
>> use-livecode at lists.runrev.com
>> Please visit this url to subscribe, unsubscribe and manage your
>> subscription preferences:
>> http://lists.runrev.com/mailman/listinfo/use-livecode
>> 
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode





More information about the use-livecode mailing list