Apple推送通知-交货收据 [英] Apple push notifications - delivery receipt

查看:111
本文介绍了Apple推送通知-交货收据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了一个简单的消息传递系统,该系统允许以推送通知的形式从Web界面向设备发送简短消息.

I wrote a simple messaging system, which allows sending brief messages from web interface to devices, in form of push notification.

在android上,一切顺利,一旦设备收到通知,便将交付确认收据发送回服务器,然后读取确认.显然,交付确认通常是在应用程序在后台运行或手机处于睡眠状态时发生的.

On android, everything went well, once device receives notification is sends delivery confirmation receipt back to server, then read acknowledgement. Obviously, delivery confirmation often happens while app is running in background or phone is asleep.

我为iOS编写了类似的应用程序.我当时对该应用程序感到多么惊讶:当应用程序处于非活动状态时,didReceiveRemoteNotification没有被调用!

I wrote similar app for iOS. How surprised I was that application: didReceiveRemoteNotification is not called when app is not active!

在应用未激活时,是否真的不可能在没有用户交互的情况下跟踪邮件传递?其他人建议将消息​​记录在服务器上,并在应用打开时发送消息,但这仍然需要用户交互.

Is it really impossible to track message delivery without user interaction when app is not active? Others have suggested keeping log of messages on server and sending them when app opens, but this still requires user interaction.

有没有办法解决苹果对后台服务的限制?我可以以某种方式使我的应用使用声音或位置服务,以允许在后台执行简单的POST请求吗?

Is there a way around apple restriction on background services? Can I somehow make my app use sound or location service, to allow simple POST request while in background?

推荐答案

在iOS7中,您可以将推送通知与后台抓取一起使用,这是设置了内容可用标志的远程通知.有效负载示例:{aps:{content-available:1}}. 在这种情况下,iOS会唤醒您的应用(有一些限制,请参见:如果iOS应用被强制退出,则iOS可以将我的应用启动到后台用户?).

In iOS7 you can use push notifications with background fetch, which is a remote notification with the content-available flag set. Example payload: {aps: {content-available: 1}}. In this case iOS will wake up your app (there are some limitations see: Will iOS launch my app into the background if it was force-quit by the user?).

应用程序唤醒后,您有30秒的时间将推送通知收据确认发送到您的服务器. 您还必须在目标"后台模式下启用背景获取"功能,并更新AppDelegate使其包含以下方法:

After your app is woken up you have 30 seconds to send to your server the push notification receipt confirmation. You'll also have to enable the "Background fetch" capability in the Target background modes and update the AppDelegate to include this method:

- (void)application: (UIApplication *)application didReceiveRemoteNotification: 
  (NSDictionary *)userInfo fetchCompletionHandler: 
  (void (^)(UIBackgroundFetchResult))completionHandler

因此,这需要您做一些工作.

So this requires a bit of work from your side.

我希望这会有所帮助.

I hope this helps.

这篇关于Apple推送通知-交货收据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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