从 PWA 向 iOS 发送推送通知 [英] Sending Push Notifications to iOS from PWA

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

问题描述

我有一个使用 Blazor WebAssembly 制作的渐进式 Web 应用程序,我想知道是否可以向 iOS 设备发送推送通知?虽然人们说如果现在可以在 MacOS 上的 Safari 上运行,Push API 的网站说它不支持 iOS 上的 Safari.

I've got a Progressive Web App which made with Blazor WebAssembly and I was wondering if I can send push notifications to iOS devices? Although people said if works now on Safari on MacOS, Push API's website says that it does not support Safari on iOS.

  • 如果我面向 iOS,是否需要包装每个网络应用程序?我没有 MacBook,是否需要购买一台才能实现这一目标?

  • Do I need to wrap every web app if I target iOS? I don't have a MacBook, do I need to buy one just to achieve this?

还有 Firebase 和 Azure 通知中心,我不能使用他们的服务发送 iOS 通知吗?Firebase 只有 Objective-C 和 Swift 示例.

Also there are Firebase and Azure Notification Hub, Can't I just use their service to send notifications for iOS? Firebase's had only Objective-C and Swift examples.

这也引出了另一个问题:通知的传输方式是否取决于平台?我对云服务在这方面的作用感到困惑.

This also led to another question: Are notifications' way of transport is platform depended? I'm confused with cloud services' role on this.

推荐答案

您只有三个主要选项才能在 iOS 上为 PWA 获取推送通知.在这两种情况下,您都必须在 Apple 开发者门户上注册一个 App ID,并获得相应服务的许可.对于选项 1,您注册的 App ID 必须具有 Apple Wallet 的权限.对于选项 2 和 3,您必须具有推送通知的权限.在这两种情况下,您都应该记录您的 Bundle ID 和 Team ID,以备日后需要.

You have only three main options to get push notifications working on iOS for a PWA. In both cases, you must register an App ID on Apple Developer portal, with permission to the appropriate service. For Option 1, your registered App ID must have permission to Apple Wallet. For options 2 and 3, you must have permission to Push Notifications. In both cases, you should record your Bundle ID and Team ID in case you need it later.

  • 选项 1(更简单):使用 PassKit 设置通用 Apple Wallet 通行证,它可以代理与原生通知非常相似的通知.这里是 一些 文档这是一个工作演示,说明如何向注册设备发送推送通知.

  • Option 1 (Easier): Use PassKit to set up a generic Apple Wallet pass, which can broker notifications that are very similar to native ones. Here's some documentation, and here's a working demo of how this can send push notifications to registered devices.

选项 2(更难):使用 Firebase 云消息传递 或者像 Node-APN 这样的包发送推送通知正确的"方式,使用来自 Apple Developer Portal 的 P12 或 P8 密钥签名.这变得很棘手,主要是因为您需要 iOS 设备标识符,它只对本地安装的应用程序公开.恐怕我没有关于如何从 PWA 中获取此设备 ID 的答案,如果没有它,此方法将不起作用.

Option 2 (Harder): Use Firebase Cloud Messaging or a package like Node-APN to send push notifications the "proper" way, signed with a P12 or P8 key from the Apple Developer Portal. This gets tricky mainly because you need the iOS device identifier, which is only exposed to applications installed natively. I'm afraid I don't have an answer on how to get this device ID from within a PWA, and without it, this method doesn't work.

选项 3(不是 PWA):您可以将应用 ID 与配置文件和 P12 或 P8 密钥一起使用,类似于前一个选项,但您将应用程序封装在 Apache Cordova,并分发它(通过公共应用商店,或使用 MDM 软件和通过私人 Apple 商务管理).

Option 3 (not a PWA): You can use an App ID with a provisioning profile and either a P12 or P8 key, similar to the previous option, but you wrap your application in Apache Cordova, and distribute it (either through the public app store, or using MDM software and via the private Apple Business Manager).

这些是您的选择.我已经用尽了所有可能的途径来研究这个,我相信至少在接下来的几个月里,这些仍然是你唯一的选择.我们可能会在未来看到对 Web Push 的进一步支持,或者只是一种从 Web 获取设备 ID 的方法,但在那之前,就是这样.目前没有任何其他方法可以解决这个问题.

Those are your options. I have exhausted every possible avenue researching this, and I am confident that these will remain your only options through at least the next several months. It's possible we may see further support for Web Push or perhaps just a way to get the device ID from the web in the future, but until that time, this is it. There aren't any other ways to go about this presently.

资料来源:我为赛百味、Gartner、摩根士丹利和普华永道(以及许多其他品牌)等主要品牌设计和开发应用程序.我的研究是最近的,包括与 Apple 的 WebKit 负责人以及世界上最重要的 PWA 和 iOS 专家之一的直接交流.

Source: I architect and develop apps for major brands like Subway, Gartner, Morgan Stanley and PwC (among many others). My research is very recent, and includes direct communication with the head of WebKit at Apple, and also with one of the world's foremost PWA and iOS experts.

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

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