Delivery report of sending remote push notificatio

2019-01-27 11:20发布

问题:

I am sending remote push notifications using APNS. The requirement is when the notification is delivered to the app user (even if the user did not tapped on the notification or even seen it) , send a delivery receipt to the web server (i.e. call a web service) according to the notification id i received.

APNS did not have a provision of delivery reports. Their is a feedback service of APNS, however that does not offer delivery report either.

So i would like to know what are the possible ways to get a delivery report of remote push notifications. If i am able to execute a custom method in APP deligate or any other when a remote push notification arrives even when the APP is in background or terminated by user then it will solve my problem.

Any help will be highly appreciated.

Below is the code i am using currently and it is not working when the app is in background.

I wrote a custom method in

-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo

to send confirmation to the server that the notification is received. When the application is in foreground all functions execute perfectly. But the problem arise when the application is in background. The custom method which is written in

 -(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo

does not execute until the user open the application by tapping the notification bar and never execute if the user open the application by tapping the app icon not by the notification bar.

回答1:

Since Apple doesn't provides any method to know when a Push Notification has delivered to user's device. Here is what you can do,

1) Add "Notification Service Extension" to your app.

2) Now add your code for calling webservice to report to your server about the Notification being received, in didReceiveNotificationRequest.

3) Now go to Capabilities of your app and enable "Background fetch" in "Background Modes".

4) Now with the notification you are sending, pass "content-available = 1", This will wake up your app for 30 sec and it can execute the code written in didReceiveNotificationRequest.

It worked for me.



回答2:

Why do you need to know this? What purpose does it serve you to know whether or not they actually received the notification on their device?

In any case, use: https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/CreatingtheNotificationPayload.html#//apple_ref/doc/uid/TP40008194-CH10-SW8

It will wake your app for 30 seconds in the background to handle it. You need to add the RemoteNotifications background capability.

If too many are sent per hour, Apple will throttle them or just not deliver them.