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

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

问题描述

做研究,试图选择一个方向通知类型。我希望能够通知我的应用程序,还有被刷新新的数据,但也懒得与弹出/通知消息的用户。这个想法是,同一个通知出去,如果应用程序是打开或关闭,当这个特殊的消息到达和应用程序是开放它知道来获取数据。

我的想法是发送一个空的APS在这条底线<一本字典一样的例子5 href=\"http://developer.apple.com/library/mac/#documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/ApplePushService/ApplePushService.html#//apple_ref/doc/uid/TP40008194-CH100-SW9\">apple文件。

我的问题是在收到此类消息时,会发生什么?它说,它会清除徽章,但将某种默认的消息显示给用户?或许这会彻底无语了?

跟进的问题,有没有一些更好的办法不是检查,如果应用程序正在运行,并告诉我的服务器开始发送特殊的有效载荷(我想通过处理一切推送)要做到这一点其他的?


解决方案

如果没有徽章,没有警报,并没有在词典中指定的声音(用于APS键),则不会出现默认消息和它将完全沉默。

在例如5你所引用的文件中再次查看。 AP可以是空的,您可以指定任何自定义的数据,因为他们的acme2键,你都会喜欢。在acme2数据为您的服务器的特殊的有效载荷可以驻留在JSON有效载荷中的一个例子。

您并不需要告诉您的应用程序运行的服务器。该服务器可以通过APNS,如果你的应用程序正在运行或不发送特殊有效载荷的过失,您将收到特别的有效载荷以两种方式(假设当然,这推确实达到设备......这是不保证的)之一:


  1. 如果您的应用程序在前台,然后将iOS版无法拦截的通知。您将收到通知您的应用程序委托的申请:didReceiveRemoteNotification:方法(前提是您的应用程序委托没有覆盖的方法)

  2. 如果iOS的那样拦截推送,那么当你选择在响应该通知启动应用程序,那么你将需要检索的推辞典在您的应用程序委托的应用中:didFinishLaunchingWithOptions:法如下面的例子:


   - (BOOL)应用:(*的UIApplication)的应用didFinishLaunchingWithOptions:(NSDictionary的*)launchOptions {
    [自应用:应用didReceiveRemoteNotification:[launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey]];
}

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 idea was to send an empty aps dictionary like example 5 at the bottom of this apple document.

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)?

解决方案

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.

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.

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. If your application is in the foreground then iOS will not intercept the notification. You will receive the notification in your app delegate's application:didReceiveRemoteNotification: method (provided that your app delegate does override the method).
  2. If iOS did intercept your push, then when you choose to launch your application in response to the notification then you will need to retrieve the "push dictionary" in your app delegate's application:didFinishLaunchingWithOptions: method as in the following example:


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

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

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