ios - 通过 APNS 在有效负载中发送的数据

标签 ios apple-push-notifications

我在我的应用程序中使用 APNS,我想发送一些数据(当然小于 256 字节)。我的问题是我想通过推送通知发送数据而不向用户显示任何警报。我怎样才能做到这一点 ? 谢谢

最佳答案

在 aps 键中指定角标(Badge),并将您的数据放入其他键中。因此,如果您使用角标(Badge)编号,请重新计算正确的角标(Badge)编号,如果您不使用角标(Badge)编号,则只需发送 0。

来自苹果文档:

Providers can specify custom payload values outside the Apple-reserved aps namespace. Custom values must use the JSON structured and primitive types: dictionary (object), array, string, number, and Boolean. You should not include customer information as custom payload data. Instead, use it for such purposes as setting context (for the user interface) or internal metrics. For example, a custom payload value might be a conversation identifier for use by an instant-message client application or a timestamp identifying when the provider sent the notification. Any action associated with an alert message should not be destructive—for example, deleting data on the device.

但有一个问题 - 这只有在应用程序正在运行时才有效。

它的工作原理是 - 如果应用程序正在运行,您将通过 didReceiveRemoteNotification 回调以及有效负载数据获得通知。您可以在此处提取自定义数据。 但是,如果应用程序未运行,通常会显示警报,并且仅当用户点击应用程序时才会通知您的应用程序。由于您不想显示警报 - 当应用程序未运行时,您无法获取自定义负载数据。仔细想想,如果应用程序自行启动,对用户来说会非常可怕。 :)

关于ios - 通过 APNS 在有效负载中发送的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15631352/

相关文章:

java - 如何从 (Java) Date 对象中获取 Expiry 字段以发送到 Apple Push Notification Services?

iphone - 图片来自 Facebook 相册

iphone - 在 iOS 上,如何使 cell.imageView 刷新其内容?

objective-c - 在子类中更改 ivar 的类(到派生类)

apple-push-notifications - 在多个苹果 channel 中使用 PushSharp

ios - 当应用程序未运行时处理 JSON 推送通知解析

ios - 将默认 UITextField 值设置为 0(计算器)

ios - 如何使用 swift 比较核心数据中同一实体的两个属性值

certificate - 为什么我无法将APNs Development iOS类型的证书添加到配置文件中

ios - 苹果推送通知一个应用多个子域