iOS notification app goes into background doesn't seem to work

Mark Smith marksmithhfx at gmail.com
Tue Nov 24 20:16:06 EST 2020


Hi Graham, figured it out. If I replace the app, and while developing I do that pretty frequently, the first “WillBecomeActive” does not get detected because the app has not yet registered for notifications. So over 48 hours I saw 3 such events and while I did not record the times I installed, if I replaced it 3 times then this data would make perfect sense. I hope that is clear, and if not feel free to ask me to explain it better. But I think the data indicate that everything is working A-OK.

Sorry for any confusion I might have caused, but at least I got to the bottom of my own problem :)  I’ll send Elanor an email to confirm and let her know. 

Mark


> On Nov 25, 2020, at 1:00 AM, Mark Smith <marksmithhfx at gmail.com> wrote:
> 
> Thanks Graham,
> 
> Nope, just checked and my quotes are not curly. Over a 48 hour period of testing, with multiple startups and shutdowns (33 in total, these were mostly in/out of background not actual exits and restarts) I only saw 3 instances of a double shutdown notification (applicationWillResignActiveNotification) without an intervening startup (applicationDidBecomeActiveNotification) so it’s evidently a very small problem (10% ?). I’ll send the log to Elanor to let her know. From my perspective, not something I am going to fret about. 
> 
>> On Nov 24, 2020, at 10:18 PM, Graham Samuel via use-livecode <use-livecode at lists.runrev.com> wrote:
>> 
>> An very timely and helpful update from Elanor at the mother ship. My problems with mergNotify were there because the string representing the specific notification “UIApplicationWillResignActiveNotification” was in curly quotes! I literally didn’t see this, and the script editor didn’t report an error. It might have done something with the colorisation, but as I’m partly colour blind I never take much notice of this aspect of scripts. How the quotes got there is a mystery, as I thought I had simply copied these lines of script from an earlier mail by Henry Lowe, but apparently not. So, problem solved at the price of my red face.
>> 
>> The question about what being “in the background” actually means remains, and I hope to have an answer for that soon. If I get any info I will send it to the list as a new topic.
>> 
>> Elanor also said:
>> 
>>> I don't know if the issue Mark is seeing is the same one but if you are replying on the list just ask him to contact Support and I'll take a look at his stack too.
>> 
>> 
>> 
>> Graham
>> 
>>> On 23 Nov 2020, at 15:23, Graham Samuel via use-livecode <use-livecode at lists.runrev.com> wrote:
>>> 
>>> Thanks Mark
>>> 
>>> Well, it does seem to be a bug, but is it in iOS or LC? It is weird that you get inconsistent results. Mine are more consistent, but still wrong. I plan to write to the mother ship and ask their opinion.
>>> 
>>> I am also getting perhaps related inconsistencies in the use of locationChanged messages to get GPS readings, or I think I am. It looks like sometimes when the app goes into the background it switches off the effect of
>>> mobileStartTrackingSensor "location"
>>> 
>>> which a script can only do by calling mobileStopTrackingSensor.
>>> 
>>> The apparent effect is that GPS readings just stop coming in, although other activity (in my case, a stopwatch-like timer) continues without a break. I am haunted by the idea that I’ve made some mistake in coding, of course, but it I haven’t then I need to know somehow that the readings have stopped and correct the situation before gaps appear in the record, i.e. within about a second. Can’t do that if I’m not notified of the switch to the background.
>>> 
>>> I have tried to look at the iOS SDK documentation but have become terminally confused - it seems to suggest that apps that go into the background are suspended and ‘do not receive events’. If that’s so, how do timer and navigation apps work? They still seem to be doing stuff even while the user is using another app to read the news, make a phone call or whatever. There must be a state between being active and just sitting in RAM and doing nothing. What is that state called and how does one invoke it?
>>> 
>>> Over my head...
>>> 
>>> Graham
>>> 
>>>> On 22 Nov 2020, at 13:30, Mark Smith <marksmithhfx at gmail.com> wrote:
>>>> 
>>>> Hi Graham,
>>>> 
>>>> So, apparently not 100% accurate but here are the results of some late hour testing yesterday (I was also interested in evaluating something I needed to occur around the time the date changed, hence the late hour testing.). But as you can see, I had 3 ResignActiveNotifications before the first DidBecomeActive occurred. 
>>>> 
>>>> 2:33:58 PM UIApplicationWillResignActiveNotification detected in SS
>>>> 
>>>> 11:22:40 PM UIApplicationWillResignActiveNotification detected in SS
>>>> 
>>>> 11:25:50 PM UIApplicationWillResignActiveNotification detected in SS
>>>> 
>>>> 11:33:19 PM UIApplicationDidBecomeActiveNotification detected in SS
>>>> 
>>>> 11:33:26 PM UIApplicationWillResignActiveNotification detected in SS
>>>> 
>>>> 1:21:48 AM UIApplicationDidBecomeActiveNotification detected in SS
>>>> 
>>>> 1:29:38 AM UIApplicationWillResignActiveNotification detected in SS
>>>> 
>>>> 
>>>> 
>>>>> On Nov 21, 2020, at 11:33 PM, Mark Smith <marksmithhfx at gmail.com <mailto:marksmithhfx at gmail.com>> wrote:
>>>>> 
>>>>> Graham, I think there might be a problem. I just re-enabled this code in one of my applications and the only thing I am seeing is the WillResignActiveNotification message, and not the DidBecomeActiveNotification message. Odd also because it is the exact opposite of what you are seeing, so we are both seeing half of the story, just not the same half :) I’ll keep it enabled and see if I can spot any patterns. 
>>>>> 
>>>>> Mark
>>>>> 
>>>>> 
>>>>>> On Nov 20, 2020, at 9:48 PM, Graham Samuel via use-livecode <use-livecode at lists.runrev.com <mailto:use-livecode at lists.runrev.com>> wrote:
>>>>>> 
>>>>>> Thanks Mark
>>>>>> 
>>>>>> I tried exactly your suggestion. For me, the second notification appears exactly as you say, but the first one doesn’t. It’s likely that I made a silly mistake but I can’t see what it is. I put other stuff in the log, so it’s not just a case of the text being overwritten. Obviously the app does go into the background, since it is detected coming back to the foreground. This test was on the Xcode simulator, but I got essentially the same results on a real iPhone.
>>>>>> 
>>>>>> Strange.
>>>>>> 
>>>>>> Graham
>>>>>> 
>>>>>> 
>>>>>>> On 20 Nov 2020, at 17:21, Mark Smith <marksmithhfx at gmail.com <mailto:marksmithhfx at gmail.com>> wrote:
>>>>>>> 
>>>>>>> Hi Graham, you can put something like the following in your handlers and then check the log file to see when they were activated.  If you're using Xcode you can download your “sandbox”  to your device. You’ll find the log file in there. 
>>>>>>> put the long time && "UIApplicationWillResignActiveNotification detected" & return after url ("file:" & specialFolderPath("documents") & "/log.txt")
>>>>>>> 
>>>>>>> for example…
>>>>>>> 
>>>>>>> 10:39:05 AM UIApplicationWillResignActiveNotification detected in Stack Script
>>>>>>> 10:57:23 AM UIApplicationDidBecomeActiveNotification detected in Stack Script
>>>>>>> 
>>>>>>> 
>>>>>>> 
>>>>>>> 
>>>>>>>> On Nov 20, 2020, at 3:23 PM, Graham Samuel via use-livecode <use-livecode at lists.runrev.com <mailto:use-livecode at lists.runrev.com> <mailto:use-livecode at lists.runrev.com <mailto:use-livecode at lists.runrev.com>>> wrote:
>>>>>>>> 
>>>>>>>> Thanks to Mark Smith and Henry Lowe, I know that I’m supposed to set up mergNotify for two notifications as below.
>>>>>>>> 
>>>>>>>> I believe I’ve done this, and I’ve set a monitoring action (putting a text into a field) to show that these notifications have happened.
>>>>>>>> 
>>>>>>>> Of course it may be just me, but so far, I only seem to get the notification when the app comes back into the foreground (so logically it must have gone the background first),  but I just don’t get the ‘going in to the background' notification, or at least my monitoring doesn’t work.  Is there some trick of timing that I’ve missed?
>>>>>>>> 
>>>>>>>> Graham
>>>>>>>> 
>>>>>>>> 
>>>>>>>>> On 17 Nov 2020, at 20:07, HENRY LOWE via use-livecode <use-livecode at lists.runrev.com <mailto:use-livecode at lists.runrev.com> <mailto:use-livecode at lists.runrev.com <mailto:use-livecode at lists.runrev.com>>> wrote:
>>>>>>>>> 
>>>>>>>>> <Thanks to Panos for this tip:>
>>>>>>>>> 
>>>>>>>>> On iOS use mergNotify as below. Works well for me.
>>>>>>>>> 
>>>>>>>>> on openStack
>>>>>>>>> mergNotify "UIApplicationWillResignActiveNotification"
>>>>>>>>> mergNotify "UIApplicationDidBecomeActiveNotification"
>>>>>>>>> end openStack
>>>>>>>>> 
>>>>>>>>> on UIApplicationWillResignActiveNotification pUserInfo
>>>>>>>>> // Your code before the app goes to background
>>>>>>>>> -- your code here to handle going to the background
>>>>>>>>> end UIApplicationWillResignActiveNotification
>>>>>>>>> 
>>>>>>>>> on UIApplicationDidBecomeActiveNotification pUserInfo
>>>>>>>>> // Your code after the app comes back to foreground
>>>>>>>>> -- your code here to handle your app becoming active
>>>>>>>>> end UIApplicationDidBecomeActiveNotification
>>>>>>>>> 
>>>>>>>>> Henry
>>>>>>>> 
>>>>>>>>> On 17 Nov 2020, at 23:39, Mark Smith via use-livecode <use-livecode at lists.runrev.com <mailto:use-livecode at lists.runrev.com> <mailto:use-livecode at lists.runrev.com <mailto:use-livecode at lists.runrev.com>>> wrote:
>>>>>>>>> 
>>>>>>>>> And just a reminder that, under iOS, you’ll have to register to receive a “ UIApplicationWillResignActiveNotification” message, and then write a handler to respond to that (PS only register once in your stack script — I learned the hard way). It’s documented under mergNotify in the dictionary (with credit to Elanor for pointing this out to me when my “on shutdownRequest” handlers were being ignored). 
>>>>>>>>> 
>>>>>>>>> Jacque, I believe this is what you are looking for to be notified when you go into the background. I do some db cleanup at that time and it seems to work.
>>>>>>>>> 
>>>>>>>>> Mark
>>>>>>>> 
>>>>>>>> _______________________________________________
>>>>>>>> use-livecode mailing list
>>>>>>>> use-livecode at lists.runrev.com <mailto:use-livecode at lists.runrev.com> <mailto:use-livecode at lists.runrev.com <mailto: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 <http://lists.runrev.com/mailman/listinfo/use-livecode>
>>>>>>> 
>>>>>> 
>>>>>> _______________________________________________
>>>>>> use-livecode mailing list
>>>>>> use-livecode at lists.runrev.com <mailto: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