Cra*_*tin 6 javascript firebase firebase-cloud-messaging
我使用的是Firebase的云端消息,但它无法在iPad和iPhone上运行.这是我能用它做的最简单的用法.我刚刚完成了关于异地通知的所有教程,但我直接在Firebase的脚本中得到了这个错误
.
您正在使用的firebase JavaScript库与iOS上的Safari不兼容.在iOS设备上运行的Safari浏览器与应用程序的桌面版本不同,并且没有相同的功能集.
在这种特定情况下,iOS Safari会在您的firebase.js库上抛出错误,尝试使用Web Notification API requestPermission()方法,以允许firebase向用户显示通知.但Notification API不存在.
您可以在此处查看对Notification API的支持:http://caniuse.com/#search=Notification
当您的Web应用程序在不支持它的移动设备上查看时,您可能必须查看替代方案或禁用firebase库.如果它应该适用于iOS Safari,那么您应该向Firebase提交一个错误,看看是否有可用的补丁或更新解决了firebase.js库中的问题.
iOS 不支持通知 API https://caniuse.com/#search=Notification
我创建了一个函数,让您知道用户的浏览器是否支持它。
const isSupported = () =>
'Notification' in window &&
'serviceWorker' in navigator &&
'PushManager' in window
Run Code Online (Sandbox Code Playgroud)
并在使用 Notification API 之前使用它
例如:
if (isSupported()) {
const hasPermission = Notification.permission === 'granted'}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2075 次 |
| 最近记录: |