I want to update status/flag without calling web service, so i implemented silent push but if app is killed then silent push will not updating my status/flag. Please tell me the other way to handle this situation.
If your app is killed, there is nothing you can do about that situation. Push will come through, but it won't automatically start the app and if its a silent push, well then you have zero chance of getting that app to start back up.
You can do one last call to a web service just before the app gets terminated - but you have seconds to do it, so not ideal.
Related
I am working on an application which allows to send messages to another user.
If I press Home Button app goes first in background and then in suspended state so I don't receive any message unless I bring app back to the foreground.
How can I fix this to receive messages even if app is in background or suspended state? Solution is to avoid app to go suspended?
Some ideas please
Thanks and regards
For that you have to use Push notifications as they will wake your app when a notification is received (in your case a message is sent to your app). Do you have this implemented?
Another Dirty way would be to keep a silent Music file playing when in background state thus the app nevel sleeps (unless terminated by user). Nut keep in mind that this trick wont let you publish your app to the app store!
Hope this helps!
Use Voip to wake the app upon receiving push notification then handle it and pull from server as you want
migrate-to-ios-voip-push-notifications
When app is not running (terminated NOT in background) and a remote push notifications is received, is there any way to inform the app about it so that the app can update something locally such as simple int counter?
I want to store something so that when the app is launched the next time, app knows that notification was received when app wasn't running and something needs to be done.
If user launches an app by tapping on a notification, obviously the app is notified about it through AppDelegate methods but these methods are never called if user launches an app by tapping on the app's icon.
To be aware of notification when user launches app by tapping on icon, i need some way to let app know that notification was received when app was in background.
There is no way you can achieve this with simple push notifications.
According to apple docs if the user has manually killed your application by swiping it out of memory, your app will never be started in the background to process data until after the user chooses to launch it again.
One solution to this problem is using VOIP push.
According to apple docs -
Your app is automatically relaunched if it’s not running when a VoIP
push is received.
But you need a strong reason for using it and apple may ask that before approving your app on the app store.
To read more about VOIP push please go through this doc - https://developer.apple.com/library/content/documentation/Performance/Conceptual/EnergyGuide-iOS/OptimizeVoIP.html
You can also be used the "Silent Push Notifications".Which are confirming that their is something available on the server, which you need to download to your app,The payload format of the Silent push notification is like
{ content-available:1 }
The Best part of the silent notification is that they do not notify the iPhone user
Here 1 is for their is something available to download from the server.
here below i have attached the apple's silent notification slide.
Your App is getting Refresh in the Background.
When I receive a remote notification I updated a counter that I save to UserDefaults and I also show a local notification. Everything works as expected when the app is in the foreground, background, and suspended states Ref. When the app is in the Not Running state my counter is not updated nor is my local notification shown.
It is my understanding that I should be able to receive and process Remote Notifications while the app is completely off. A few articles online claim that when a Remote Notification arrives while in the Not Running state that the application:didFinishLaunchingWithOptions: should be called followed by application: didReceiveRemoteNotification:fetchCompletionHandler: but in my case it is not.
Is it possible to receive remote notifications while in Not Running state?
If your app is a VoIP app and you are using VoIP pushes through PushKit then a push notification will launch your app from the terminated state in order to deliver the notification. If you are using standard push notifications then your app will not receive the notification if it is terminated. You can include an alert text with a 'silent' notification that will be displayed to the user in the event that your app is terminated in order to prompt them to launch your app.
First of all, it sounds like you have a silent notification set up. Once you add alert data to your push notification (information like the title, body etc.. you can find more on that here), it'll start to display on the lock screen.
Second, it's not possible for your application to launch from a push notification, silent or otherwise, if it's in the Not Running state. The documentation on this is actually incorrect, as it states that the application will only not be launched if the user has quit the app. However, this actually also applies for any circumstance under the not-running state, for example if your app has never been launched since installation/rebooting, or if it was quit due to memory (a fairly common occurrence - iOS purges apps which haven't been run recently as required).
did you check this mark when app is background?
I have implemented AWS SNS push notification service.
We have an issue which is explained below :
Scenario :
We are trying to save the notification message we receive as a part of requirement.
When the app is killed (swipe out from recent apps) we are able to receive notification, also we are able to save the notification message when we open the message directly from the notification panel it works fine,but when we open the app directly the notification message is not getting saved.
In short we are not able to know if we had received a notification message if we directly open the app rather than clicking the message from the notification panel.
Is this default behavior ? or is there any work around for this ?
Have looked into many posts on about Push Notifications but haven't seen any threads pointing to this scenario.
This is a normal behavior, and there is no workaround.
If your app is killed by the user, it won't be able to run ANY code before it's manually launched again.
If it's manually launched from a notification, this notification's payload will be handled by your AppDelegate.
On top of that, don't forget that Push notifications are Best Effort. That means that they are not reliable, they can be heavily delayed or never delivered at all. Don't rely on Push notifications to achieve any critical work.
If you need to keep a copy of your notifications in-app, keep them server side and fetch them as you would do with any other object.
In order to execute code when the app is killed by the user you need to implement VOIP using PushKit framework provided by apple.
VOIP push unlike regular push notification enables the app to become active even if the app is killed by user.
I haven't found the exact answer to this elsewhere on this site. The goal is to send a silent remote notification (no user alert/badge/sound) to my app, with a custom payload, and then have the app process this even if it was not running when the notification was received. If the app was not running, is it notified and given a chance to process the (silent) notification? Or is it only notified the next time the app is launched?
So far, I've only been able to confirm that you can receive a non-silent notification when the app is not running, or a silent notification when the app IS running. I haven't seen confirmation of what happens if you receive a silent notification and are not running.
Essentially, the answer that I've been able to find so far (and #Sebrassi concurs with above) is that what I am asking for is not possible. The app does not get any processing time when a notification comes in, period, unless it is already running or the user launches it via the UI in one way or another.