Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
510 views
in Technique[技术] by (71.8m points)

objective c - Delivery report of sending remote push notifications using APNS - IOS

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...