在 iOS 上的推送通知中使用通用链接进行深度链接

Using Universal Links for DeepLinking in Push Notifications on iOS

我正在调查在推送通知中使用通用 Links 以深入 Linking 到 iOS 应用程序。这样我就可以面向未来的网络。 许多示例和教程都假定用户将 select 从网站到 link 应用程序的通用 link。 我想在 Push Notifications 中使用 Universal Links 而不是常规的 URL Schema 方法。 我已经阅读了苹果文档 https://developer.apple.com/library/content/documentation/General/Conceptual/AppSearch/UniversalLinks.html

但是,我现在不清楚如果我只是使用通用Link通过推送通知打开应用程序,我是否还需要设置所有配置,例如创建和上传一个 apple-app-site-association 文件到网络服务器的根目录。

这种在 Push Notifications 中使用通用 Link 的方法是否深入 Link 到应用程序的某个区域是推荐的方法,因为 Apple 似乎不鼓励使用 URL Schema 是一般情况还是 Push Notifications 是特例?

推送通知和通用 Link 是两种不同的动物,尽管它们都用于让用户进入应用程序。

使用通用 Link 时,iOS 设备上的 Safari 会首先打开,以防未安装该应用程序。如果该应用程序存在,用户会立即从 Safari 跳转到该应用程序,并将 URL 传递给 AppDelegate 方法 application(_:continue:restorationHandler:)。如果该应用程序不存在,Safari 会打开通用 Link 的 URL。此处需要设置 apple-app-site-association 文件以验证您拥有相关目的地 URL,并且可以将用户从网站重定向到应用程序。通用 Link 更适合 user-initiated 交互(点击电子邮件中的 link 等)

另一方面,推送通知通过 TCP/IP 直接与设备通信,将消息从 APNs 传递到 iOS 设备(有关此结构,请参阅 APNs Overview for more info). Safari isn't involved and the user taps the notification on the iOS device (for example) to open the notification and go to the destination. Your destination isn't passed by URL like with Universal/deep links, but with extra JSON in the notification payload that you can process in your app (see Creating the JSON Dictionary)。由于不涉及网站,因此没有 apple-app-site-association 推送通知。您直接从 APNs 与您的应用程序通信,并且通常使用证书来确保只有您可以使用推送通知打开您的应用程序。远程推送通知非常适合 developer-initiated 交互以吸引用户。

希望这有助于澄清事情!