PC SOFT

FORUMS PROFESSIONNELS
WINDEVWEBDEV et WINDEV Mobile

Accueil → WINDEV Mobile 2024 → [WM23] Local Notification iOS
[WM23] Local Notification iOS
Débuté par ARV, 05 sep. 2019 23:55 - 18 réponses
Membre enregistré
498 messages
Popularité : +8 (8 votes)
Posté le 05 septembre 2019 - 23:55
Hi

I have a question about this...

I put some code about Local Notification on the event background of the project, but it doesn't launch nothing...

I also create a infinite thread with 5 seconds of execution between calls with a local notif add but nothing happend

Someone know what it's happening?
is it possible to launch local notification on the iOS on the background event?

--
Best Regards
ARV
Posté le 06 septembre 2019 - 03:24
IOS does not allow long running background processes (is not like android) the OS by design will take the app through a variety of stages until it shut it down. That behavior is by design.
Membre enregistré
498 messages
Popularité : +8 (8 votes)
Posté le 06 septembre 2019 - 15:20
Hi WindevCol

I see...
but is it possible to launch a local notification?
I tried but it doesn't launch it.

--
Best Regards
ARV
Posté le 09 septembre 2019 - 22:47
you need to do that on a separate thread or it will not work
Membre enregistré
498 messages
Popularité : +8 (8 votes)
Posté le 10 septembre 2019 - 15:22
Hi WindevCol

I will give it a shot

but Can I use an automated procedure Thread?
How many times I can repeat it?
it will shut down my automated procedure?

then again I will test with a single thread and main thread to see what happends.
Thanks for the idea!

--
Best Regards
ARV
Membre enregistré
498 messages
Popularité : +8 (8 votes)
Posté le 10 septembre 2019 - 16:45
Hi

Just to make clear this is my situation

I have a socket, the socket will read every 5 seconds.
if the app it's on background I need to launch notifications to the user if theres something new on the socket.
I try to put it just to test a local notification but nothing seems to work.

that's why I'm asking if 5 seconds it's to much for iOS that shut down my notification.
Then again I test it using a single thread on background event and nothing show up.

I know how to launch the notification
I know how to set a thread every time to time to execute

but I can't let it work on iOS there's something missing, like you say before WindevCol for iOS if there a execution iOS doens't want it it will shut down.

but I need to launch a notification when the socket have something.
I know how to handle it, but I'm not sure about the local notification...

--
Best Regards
ARV
Posté le 10 septembre 2019 - 18:10
@ARV what you are trying to do will never ever work, read the documentation about IOS application lifecycle, does not matter how you do it the OS will KILL all those processes after short time. That type of pulling in the background is not permitted on IOS by design. Because they dont want any application draining the phones power or resources. so after a very short period of time after you application has gone into the background the application and all its processes will be killed by IOS itself and there is nothing you can do about that. Because by design on IOS you are NOT suppose to do what you are trying to do. On Android it will always work because Android does not have those types of restrictions.
Membre enregistré
498 messages
Popularité : +8 (8 votes)
Posté le 10 septembre 2019 - 18:36
Hi

I test the thread local notification and it work
just like 5 seconds it takes to show up.

Now I need to launch notification when my socket have something, so I need to read my socket time to time, I will test on what I can do with this...
Any idea it could be great!

--
Best Regards
ARV
Posté le 10 septembre 2019 - 19:01
The reading of the socket is where the problem is going to be when the application is on the Background, as long as the application its on the Foreground it will work with the thread like i told you and like you already saw it works. the problem begins when the application goes into the background and the application release cycle on the OS begins. That is where the problem is going to be. What you are trying to do it will always work when the app its on the foreground.
Membre enregistré
498 messages
Popularité : +8 (8 votes)
Posté le 10 septembre 2019 - 22:08
Hi WindevCol

Yes you are right!

and yes that's the problem right now, when the app it's on background.
I try to put an automated thread, this thread will execute on 5 seconds each call, and it doesn't launch the notification.
I guess it's because the iOS shut down this process

so theres no way to make it work?

Thanks for your replys!

--
Best Regards
ARV
Posté le 10 septembre 2019 - 22:19
I am always willing to help @Arv and the answer is NO, unfortunately on the background there is no way to make it work, because the Lifecycle process of an IOS application while is on the background will kill it. Have you considered using PUSH notifications ? i am guessing on that socket you are receiving the events from a server.... so why dont you make a service that monitors those events on the server side and send a PUSH notification to your IOS app when someting happens.... that will definitely work even if your app in on the background or closed. Because that is what PUSH notifications have been designed for.
Membre enregistré
10 messages
Posté le 11 septembre 2019 - 00:33
hello ARV,
As friend WindevCOL said, IOS has limitations for this type of execution, but it is possible to do something, you need to use backgroud tasks, I don't know if I understand correctly, but will you get data from a server using socket? If it is, I recommend using PushNotification, it would be much better suited for that.

Look this
https://help.windev.com/en-US/index.awp…
Message modifié, 11 septembre 2019 - 00:37
Posté le 11 septembre 2019 - 14:57
@VILANI, i do not believe that Background tasks will help @Arv if you read the documentation from PCSOFT they also explain the Background task has to be as fast as it can be because otherwise it will not be executed. The reason for that is the OS and the lifecycle of an IOS application, there is no way around it. Apple will never allow an application to stay alive in the background for an indefinitely period of time pulling on a socket on times intervals. That is not what the PCSOFT background tasks are design for on IOS. his best chance to make it work like i said before is to implement a push notification system and forget the Background task and the socket. (At Least in IOS)
Membre enregistré
498 messages
Popularité : +8 (8 votes)
Posté le 11 septembre 2019 - 17:53
Hi everyone

Thanks for all the replys and ideas.

WindevCol wrote:
> I am always willing to help @Arv and the answer is NO, unfortunately on the background there is no way to make it work, because the Lifecycle process of an IOS application while is on the background will kill it. Have you considered using PUSH notifications ? i am guessing on that socket you are receiving the events from a server.... so why dont you make a service that monitors those events on the server side and send a PUSH notification to your IOS app when someting happens.... that will definitely work even if your app in on the background or closed. Because that is what PUSH notifications have been designed for.

Thanks for the idea WindevCol, but I already use it, and I don't have full control of the push notification, the value information I have on my socket needs to be inform right away, I have something to show, so the Push notification it doesn't appear when the socket have something so what I mean it's the notification and socket return needs to be processing in the exact same time, that's why I really want to make a local notification.
Because the user will be confused, the device will tell him to open the app but the info was already give it to the app so there's no news, other times works fine in the exact same time, but not always.



VILANI wrote:
hello ARV,
As friend WindevCOL said, IOS has limitations for this type of execution, but it is possible to do something, you need to use backgroud tasks, I don't know if I understand correctly, but will you get data from a server using socket? If it is, I recommend using PushNotification, it would be much better suited for that.

Look this
https://help.windev.com/en-US/index.awp…
Message modified, September, 11 2019 - 12:37 AM


Thanks for the idea VILANI but I already test it, and works great the only problem it's needs to be executed on 15min and I need to be every 5 seconds I read the socket, so it doesn't work for me, but I could use it in another project when I have to execute something in particular.
Like I said before I was using push notification but it not always get on the device in the exact same time the socket have something to process.
sometimes it will be the two of them on the exact same time, but other times it doesn't go like that, the socket will process the info and then waaay after that the push notification appear, the user will open the app but then again it will no show what's new because the user already see it.


Thanks for all the ideas and replys I really appreciate it.
I will think what could help me on my situation, maybe I will get back to push notifications.
maybe I could manage when I want to send the push notification or not, Who knows but when I have the answer I will post it here for someone having the exact same problem as mine.

then again thanks!

--
Best Regards
ARV
Membre enregistré
498 messages
Popularité : +8 (8 votes)
Posté le 11 septembre 2019 - 18:01
Hi

another thing to add because I forgot

sometimes the push notification doesn't appear on the device, my server send it to the device, but this one doesn't ever appear, I need to send it again to see it on my device.
I'm not sure what I'm doing wrong.
I use the exact same example of windev but this issue happend not very often but it appears.

The only way different thing I don't use from the example it's to have the ID Push notification by a webservice.
I do it manually saving directly to my server.
Not sure if this could be a reason to fail sometimes.

another thing to be sure.
if my device was shut down.
Then the service send me a push notification.
When I turn on the device the notification will pop up or not?


Thanks for your time it's always really helpful

--
Best Regards
ARV
Posté le 12 septembre 2019 - 16:19
yes in theory when you restart the phone or when you turn off and on, if you have implemented the Push notification correctly it should pop up the push notification
Posté le 12 septembre 2019 - 16:30
but the phone MUST BE ON and already on the OS for the notification to pop up.... if your message is sent when the phone is OFF is must likely that the message WILL NOT arrive to the user ones he turns his phone ON. this is because on Android FCM has a default TTL value of 0, meaning the messages need to be delivered NOW OR NEVER. You could play with the time_to_live parameter to force FCM to try to keep/store the message and try to deliver it when the user its online again.
Membre enregistré
10 messages
Posté le 13 septembre 2019 - 05:30
good night, I do not understand very well how you are sending the notification of PUSH, I use on Android with FCM and IOS APN, in both cases the client is offline, once reconnected customers receive the notification, in FCM by default the messages could stay up to 4 weeks waiting, I'm not sure if that changed, in IOS the period was shorter, I don't remember exactly, but it was stored for a few days, in IOS in production I had no problem losing notification, but in the environment sandbox some crashes may occur
Membre enregistré
498 messages
Popularité : +8 (8 votes)
Posté le 18 septembre 2019 - 19:43
Hi everyone,

sorry for the late reply

I see, but what it's that parameter? the parameter that could force the FCM to try to keep sending my message

What I'm using is this:
https://help.windev.com/en-US/…

I set everything like this (or the example of PCSoft of sending Notifications called "WD Send Push")
and I don't see anything about playing with a parameter.
I use it for both situations Android and iOS.

Or are you telling me to go to the config of the service of Google and Apple and manage it from there?
actually Not sure what is this about...
sorry.

--
Best Regards
ARV