使用 APNS 发送远程推送通知的交付报告 - IOS [英] Delivery report of sending remote push notifications using APNS - IOS

查看:32
本文介绍了使用 APNS 发送远程推送通知的交付报告 - IOS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 APNS 发送远程推送通知.要求是当通知被传递给应用程序用户时(即使用户没有点击通知甚至没有看到它),根据通知 id 向网络服务器发送一个传递回执(即调用网络服务) i已收到.

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 没有提供交付报告.他们是APNS的反馈服务,但也不提供交付报告.

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

所以我想知道获取远程推送通知交付报告的可能方法是什么.如果我能够在远程推送通知到达时在 APP deligate 或任何其他方法中执行自定义方法,即使 APP 在后台或被用户终止,那么它将解决我的问题.

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.

任何帮助将不胜感激.

下面是我当前使用的代码,当应用程序在后台时它不起作用.

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

我在

-(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.

推荐答案

因为 Apple 没有提供任何方法来了解何时推送通知已发送到用户的设备.这是你可以做的,

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) 向您的应用添加通知服务扩展".

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

2) 现在在 didReceiveNotificationRequest 中添加用于调用网络服务的代码,以向您的服务器报告收到的通知.

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

3) 现在转到您应用的功能并在后台模式"中启用后台获取".

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

4) 现在使用您发送的通知,传递"content-available = 1",这将唤醒您的应用 30 秒,并且它可以执行 didReceiveNotificationRequest 中编写的代码.

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.

它对我有用.

这篇关于使用 APNS 发送远程推送通知的交付报告 - IOS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆