我们可以从 iOS 设备向 APNs 发送推送通知吗? [英] Can we send push notification to APNs from iOS device?

查看:24
本文介绍了我们可以从 iOS 设备向 APNs 发送推送通知吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在不使用后端服务器的情况下将推送通知从 iOS 设备发送到另一台 iOS 设备.iOS 设备是否可以充当服务器并向 APNs 服务器发送推送通知?提前致谢.

I want to send push notification from a iOS device to another iOS device without using backend server. Is it possible for an iOS device to act like a server and send push notification to APNs server?. Thanks in advance.

推荐答案

理论上,您可以将 Apple 推送通知从一台设备直接发送到另一台设备.您只需要应用的推送证书、您要向其发送通知的设备的设备令牌,以及与 APNS 服务器建立安全 TLS 连接的代码.

Theoretically you can send Apple Push Notifications from a device directly to another device. All you need are the push certificate of the app, the device token of the device you are sending the notification to, and code that establishes a secure TLS connection to the APNS servers.

然而,有几个实际问题使得使用服务器几乎是强制性的:

However, there are several practical problems that make the use of a server almost mandatory :

  1. 您需要一个地方,安装您的应用的所有设备的所有设备令牌都将发送到并保存在其中.最好的地方是服务器.如果没有服务器,设备 A 如何将其设备令牌发送给其他想要向其发送推送通知的设备?

  1. You need a single place where all the device tokens of all the devices that installed your app will be sent to and persisted in. The best such place would be a server. Without a server, how would device A send its device token to other devices that want to send it push notifications?

Apple 要求您尽可能长时间地保持与 APNS 服务器的连接,并使用相同的连接发送许多通知.如果您在您的设备上打开与 APNS 服务器的连接,它可能是短暂的(因为设备频繁切换网络,并且不会一直保持与互联网的连接).因此,如果您尝试频繁发送许多通知,并且每次都使用新的 APNS 连接,您可能会被禁止(因为 Apple 会将其视为 DDoS 攻击).

Apple require that you keep connections with the APNS server open for as long as possible and use the same connection for sending many notifications. If you open a connection to APNS server on your device, it will probably be short lived (since devices switch networks frequently, and don't stay connected to the internet all the time). Therefore, if you try to send many notifications frequently, and each time use a new connection to APNS, you will probably be banned (since Apple would treat this as DDoS attack).

如果您将推送证书存储在安装您的应用程序的每台设备中(以允许它直接向其他设备发送推送通知),除了将证书存储在许多地方的安全问题之外,您还将拥有每次推送证书到期时(每年一次)发布应用程序的新版本,推送通知将停止为未升级到新版本的用户工作.

If you store the push certificate in each device that installs your app (to allow it to send push notifications to other devices directly), aside from the security issue of storing the certificate in many places, you'll have to publish a new version of your app each time the push certificate expires (once a year), and push notifications would stop working for users who don't upgrade to the new version.

这篇关于我们可以从 iOS 设备向 APNs 发送推送通知吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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