使用客户端读取 APNS 有效负载
我想知道发送 APNS 通知时客户端上的应用程序是否能够读取有效负载中的数据?
例如,如果 APNS 通知显示“Hello world!”,并且用户单击“查看”转到应用程序,则应用程序是否可以通过某种方式看到 APNS 通知显示“Hello world!”。
谢谢。
I was wondering if it is possible for the app on the client to be able to read the data in the payload when an APNS notification is sent?
For example, if the APNS notification said "Hello world!", and the user clicked 'View' to go to the app, would there be a way for the app to see that the APNS notification said "Hello world!".
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
APNS 通知与特定令牌绑定,该令牌与单个手机上的特定应用程序关联。当通知到达时,iPhone OS 会向用户显示警报、播放声音(如果指定)并设置应用程序徽章(如果有)。
如果应用程序正在运行并且屏幕未处于休眠状态,则应用程序将运行并移交有效负载 JSON 数据包。如果应用程序正在运行并且屏幕是暗的,则会向用户显示警报,并通过一个按钮解锁屏幕,然后将有效负载交给应用程序。如果应用程序未运行,用户可以选择“查看/取消”。如果他们点击“查看”,应用程序就会运行并移交有效负载 JSON。
正如您所看到的,在所有这些情况下,包含通知警报、声音、徽章以及您发送的任何其他额外位的 JSON 数据包都会移交给应用程序。该文档向您展示了如何检索 JSON 数据包。如何处理它取决于您。
如果您正在考虑某个应用程序会看到负载流向另一个应用程序,那么答案是否定的。通知与特定应用程序签名相关联。
APNS notifications are tied to a specific token which is associated with a specific app on a single phone. When the notification arrives, iPhone OS shows the user the alert, plays the sound (if specified), and sets the application badge (if any).
If the app is running and the screen isn't asleep the app is run and the payload JSON packet is handed over. If the app is running and the screen is dark, the user is shown the alert with a single button to unlock the screen then the app is handed the payload. If the app is NOT running the user is given a View/Cancel choice. If they tap View, the app is run and the payload JSON is handed over.
As you can see, in all these cases the JSON packet containing the notification alert, sound, badge, and any other extra bits you send is handed over to the application. The docs show you how to retrieve the JSON packet. It's up to you what to do with it.
If you're thinking of an app seeing the payload headed for another app, then the answer is no. Notifications are tied to specific apps signatures.