Achieving Notifications after killing app similar to WhatsApp - ios

We are trying to achieve a notification feature similar to WhatsApp(iOS version) notification handling, even after killing WhatsApp explicitly- notification message appears on top chat with new message with message count – This can be achieved thru VOIP Push.
Would like to understand whether financial App can use VOIP and whether this will not cause a rejection of the app.

Your app will get rejected with the reason as,
2.16: Multitasking apps may only use background services for their intended purposes: VoIP, audio playback, location, task completion, local notifications, etc.
We found that your app uses a background mode but does not include functionality that requires that mode to run persistently.
Your app has to support VOIP if you intend to use VOIP push.
Note that if you just want to show badge count without showing notification, then it can be achieved through silent notification.
iOS shows badge count irrespective of application running state, i.e. even if your app is explicitly killed, on receive of silent notification, badge count will be reflected. Note that, app is not waken up if it is killed.
Your payload should be,
{
"aps" :
{ "content-available" : 1
"badge" : 5
}
}
Check out some good tutorials on Silent Push Notifications
https://blog.layer.com/how-we-leverage-ios-push-notifications/
https://www.raywenderlich.com/123862/push-notifications-tutorial

Related

Are silent notifications received with background notifications turned off, while application is running in iOS?

I just took a look at Is Silent Remote Notifications possible if user has disabled push for the app?.
It basically says the Silent Notifications disregard notification settings for user. It then says:
Users still have the ability to switch off your app’s ability to
process a “silent push” by means of the “Background App Refresh”
control. Even though Apple Push Notification service (APNs) will
deliver a push marked “content-available” to your phone, the OS will
not wake up your app to receive it, effectively dropping it on the
floor.
This is confusing to me. I want to make silent notifications go out only while the app is open, to update state of the app while in use only. So I wouldn't care if background app refresh is off because I wouldn't need to "wake up [my] app to receive it".
Secondarily Silent push notifications only delivered if device is charging and/or app is foreground talks about needing to have your phone plugged in to receive these notifications.
Both questions are from iOS 8, which is quite a ways back. Do they hold up all this time?
My answers are based on observation and my work on the apple notification.
Before iOS 13
Silent notification is not received even if notification is force killed by the user even if the background app refresh is on. Silent push received in case of foreground, background or killed by iOS
After iOS 13
Silent notification are received always if background app refresh is on.But if background app refresh is off silent push received only in foreground and background case.
If you want to only send silent push in foreground or background you should not add background mode in capability in Xcode. So it will receive only when the application is in the foreground or background

What is the best way to handle silent push notifications in iOS

We need to calculate some numbers and display the calculations in local notification on receiving a silent push message from the server.
This works when the app is active/open in background.
This does not work if the app is killed/not in background.
So is there anyway to perform tasks when app is closed and the silent push arrives?
FYI I have enabled background fetch.
Apple's Documentation states:
Note: The ability of APNs to deliver remote notifications to a nonrunning
app requires the app to have been launched at least once.
On an iOS device, if a user force-quits your app using the app
multitasking UI, the app does not receive remote notifications until
the user relaunches it.
The second sentence pertains directly to your question; likely not the answer you hoped for...
↳ Configuring Remote Notification Support

iOS 10 Remote Notifications When App Not Running

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?

Invoke iOS app at specific time and date

I want my iOS app to know when a specific date and time arrives without any failure. Now this time can be in days/weeks/months and my application can be in backgorund Or in terminated state.
So there are following options:
a. Local notification -- but it doesn't notify when my app is in background.
b. Silent Push notification -- it will work but it requires us to built server for same.
Is there any other option with which we can achieve same?
There is no way you can achieve this,
Your options are :
1) By using local notification like schedule notification on particular time and store that time and related activity in userdefaults. whenever app state changes to background to foreground in appdelegates - (void)applicationDidBecomeActive:(UIApplication *)application method write a code to handle desired functionality.
2) Silent push notification, which works only when your app is in background/minimized state. Once your app is Killed(swipe up from multitasking), even silent push notification cannot wake up your app.
3) To overcome the limitations of silent push notifications, Apple introduced Pushkit Notifications in iOS8, for voip apps like whatsapp, Skype, etc, in which push kit notification once received, wakes up your app even it is terminated or not running in background. Again you cannot use Pushkit unless you are actually using voip.
No. Sounds like you have to use push notifications.
This is the only thing that would work if your app is terminated.

How to debug a silent remote notification

I couldn't find anywhere how to debug a silent remote notification.
I know that a normal remote notification can be debugged by setting the project scheme to "wait for executable to be launched" but since a silent remove notification doesn't open the app, it didn't work.
I'm also not sure which method should be called when i get a silent remote notification.
Already tried:
-application:didFinishLaunchingWithOptions
-application:didFinishLaunching
-application:didReceiveRemoteNotification
-application:didReceiveRemoteNotification:fetchCompletionHandler
-application:handleActionWithIdentifier:forRemoteNotification:completionHandler
None of these worked...
This is my payload:
{
"aps": {
"content-available": 1,
"sound":"silent.wav"}
}
Can anyone help me with that?
What's happening is you've got an incorrect payload. In order for it to be considered a silent push notification that will trigger a background fetch, the only thing allowed in the "aps" dictionary is "content-available":1. Since you have a sound, the system ignores the content-available part and sends it on as a regular notification. And since there's no "alert" portion, there's no notification to interact with and no way to launch your app. Remove the sound part and your notification will come through -application:didReceiveRemoteNotification:fetchCompletionHandler
It makes no difference if your app is running in the background or hasn't been started on the device. If the app is not running, iOS will wake it up and deliver the notification after the app launches in the background. If it's been run but it's backgrounded or it's running in the foreground, the notification will simply be delivered to your app. No matter what it still goes to the same method.
There are two other requirements for this to work:
Your device has to have background fetch enabled for your app.
You can't have killed the app manually by swiping up from the multitasking UI. If you do this, iOS will NEVER wake up the app until it is ran by the user again.

Resources