带有空 aps 字典的 iOS 推送通知 [英] iOS Push Notifications with empty aps dictionary

查看:23
本文介绍了带有空 aps 字典的 iOS 推送通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

进行研究以尝试为通知类型选择方向.我希望能够通知我的应用程序有新数据要刷新,但不会用弹出/通知消息打扰用户.这个想法是,如果应用程序打开或关闭,相同的通知就会发出,当这个特殊"消息到达并且应用程序打开时,它知道获取数据.

Doing research to try and pick a direction for notification types. I'd like to be able to notify my app that there's new data to be refreshed but not bother the user with the popup/notification message. The idea is that the same notifications go out if the app is open or closed and when this "special" message arrives and the app is open it knows to fetch data.

我的想法是在此苹果文档.

我的问题是当收到这种类型的消息时会发生什么?它说它会清除徽章,但会向用户显示某种默认消息吗?或者这会完全沉默?

My question is what will happen when this type of message is received? It says it'll clear the badge but will some sort of default message appear to the user? Or will this be completely silent?

后续问题,除了检查应用程序是否正在运行并告诉我的服务器开始发送特殊"有效负载(我想通过推送处理所有内容)之外,还有其他更好的方法吗?

Follow up question, is there some better way to do this other than checking if the app is running and telling my server to start sending "special" payloads (I'd like to handle everything through push)?

推荐答案

如果字典中没有指定标志、警报和声音(对于aps"键),则不会出现默认消息,并且将完全沉默.

If there is no badge, no alert, and no sound specified in the dictionary (for the "aps" key) then a default message will not appear and it will be completely silent.

再次查看您引用的文档中的示例 5.aps 可以为空,您可以像使用acme2"键一样指定您想要的任何自定义数据.acme2"数据是您的服务器的特殊"负载可以驻留在 JSON 负载中的一个示例.

Look again at example 5 in the document you referenced. aps can be empty, and you can specify whatever custom data you would like as they do with the "acme2" key. The "acme2" data is an example of where your server's "special" payload could reside within the JSON payload.

您无需告诉服务器您的应用正在运行.无论您的应用程序是否正在运行,服务器都可以通过 APNS 发送特殊负载,您将通过以下两种方式之一接收该特殊负载(当然,假设推送确实到达了设备......这不能保证):

You don't need to tell the server that your app is running. The server can send the special payloads through APNS regardless if your app is running or not, and you will receive that special payload in one of two ways (assuming of course that the push does reach the device... which is not guaranteed):

  1. 如果您的应用程序在前台,那么 iOS 将不会拦截通知.您将在应用委托的 application:didReceiveRemoteNotification: 方法中收到通知(前提是您的应用委托确实覆盖了该方法).
  2. 如果 iOS 确实拦截了您的推送,那么当您选择启动应用程序以响应通知时,您将需要在应用程序委托的应用程序中检索推送字典":didFinishLaunchingWithOptions: 方法,如下例所示:

<小时>

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    [self application:application didReceiveRemoteNotification:[launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey]];
}

这篇关于带有空 aps 字典的 iOS 推送通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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