Sah*_*nov 6 push-notification apple-push-notifications firebase firebase-cloud-messaging
Firebase 消息推送通知在桌面和 Android 网络浏览器上没有任何问题,但是当我在 IOS 设备上测试它时,我使用哪个浏览器并不重要,通知和 .getToken() 方法不起作用。我的 JavaScript 代码是:
if ('Notification' in window) {
var messaging = firebase.messaging();
if (Notification.permission === 'granted') {
subscribe();
}
$('#notify').on('click', function () {
subscribe();
});
}
function subscribe() {
// ??????????? ?????????? ?? ????????? ???????????
messaging.requestPermission()
.then(function () {
// ???????? ID ??????????
return messaging.getToken()
.then(function (currentToken) {
console.log(currentToken);
if (currentToken) {
sendTokenToServer(currentToken);
} else {
console.warn('?? ??????? ???????? ?????.');
setTokenSentToServer(false);
}
})
.catch(function (err) {
console.warn('??? ????????? ?????? ????????? ??????.', err);
setTokenSentToServer(false);
});
})
.catch(function (err) {
console.warn('?? ??????? ???????? ?????????? ?? ????? ???????????.', err);
});
Run Code Online (Sandbox Code Playgroud)
iOS 上的所有浏览器本质上都是 WebKit(Safari 中使用的浏览器引擎)的包装器,因此它们从那里继承了大部分功能和限制。不幸的是,Safari 仍然不支持 Firebase Cloud Messaging 所需的 Web Push API。
另见:
| 归档时间: |
|
| 查看次数: |
4938 次 |
| 最近记录: |