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

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

问题描述

我正在使用APNS发送远程推送通知。要求是将通知发送给应用程序用户时(即使用户未点击通知或甚至没有看到通知),根据通知ID i向Web服务器发送送达回执(即调用Web服务)接收。

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.

任何帮助将受到高度赞赏。

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.

我写了一个自定义方法

-(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)现在添加用于调用webservice的代码,在 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天全站免登陆