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.
Related
Right now I have a framework that receives a silent notification, get the data from it (custom data) and translate it into a local notification to show the alert to the user (this is donde in didReceiveRemoteNotification:fetchCompletionHandler method). I have implemented this framework on an app and everything seems to be working correctly, silent notifications are being process when the app is in background and foreground. However, when the app is killed by the user or it is not running, I cannot receive notifications because of this:
Use this method to process incoming remote notifications for your app.
Unlike the application:didReceiveRemoteNotification: method, which is
called only when your app is running in the foreground, the system
calls this method when your app is running in the foreground or
background. In addition, if you enabled the remote notifications
background mode, the system launches your app (or wakes it from the
suspended state) and puts it in the background state when a remote
notification arrives. However, the system does not automatically
launch your app if the user has force-quit it. In that situation, the
user must relaunch your app or restart the device before the system
attempts to launch your app automatically again.
The reason I use this method for showing notifications is because the payload I sent to APNS has custom data with key-values that indicate how the notification must behave.
I've been doing some research and I found that Pushkit for VoIP can do the job. However, many post suggest that this can cause app rejection.
So my question is, how can I achieve receiving remote notifications even if my app was killed and considering that data in the payload has custom information to build the notification?
Silent push notifications are unreliable: they might get delayed, delivered in groups or even not delivered at all.
If you need to modify the content of the notification before presenting a banner for the user, you should use a Notification Service App Extension. You can also share some information between your app and this extension - using app groups or the keychain - if it needs something from your app to process the notification data.
I'm using Firebase to send silent remote notification to an iOS app. When running the app from Xcode it works fine both when the app is in foreground and background. It's fast and it works.
But, if I stop running from Xcode and start app from my device the notifications is not received regardless if the app is in the foreground or background. Sometimes I get the notification after 15+ minutes, but not always. Sometimes the notification appears if I open the app.
My notification have priority 10, content_available true and data. It does not have a title/body since I only wan't to trigger a network request and the show a local notification to the user based on the result of the network request.
Any ideas why this is?
Edit: If I include a title/body in the payload, the notification is delivered directly even without running from Xcode, but it doesn't seem to allow me to run code in the background until the notification is activated (application:didReceiveRemoteNotification:userinfo is not run).
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'm using a combination of Firebase and Batch for a chat like application.
When a push notification is received the app should be able to perform some tasks based on the data received in the notification.
From my understanding this can only be done in app states suspended -> active and not terminated.
I have it working when the app is in the foreground and also when closing the app via home button.
Should the device be locked however, didReceiveRemoteNotification:fetchCompletionHandler: is never called. At least not until the user interacts with the notification from notification center.
Is this correct? Can no work be done on a remote notification if the device is locked?
I have all the appropriate entitlements and "content-available":1 set correctly.
Is there another way that I can wake the app up from a notification and do a few background tasks? I also tried using Notification Service Extension but had the same issue with nothing happening while the device was locked.
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