3
嘗試爲我的網站實現Safari推送,我遇到了一個問題:單擊按鈕後,回調函數返回的權限等於「拒絕」,沒有任何彈出窗口出現。下面SAFARI 10.0.1 Safari推送請求權限返回「拒絕」012.1
代碼上執行控制器,其用於映射example.com/v1/log
file_put_contents ('./files/log.txt', json_encode ($_REQUEST));
,並將其寫入 '[]';
我嘗試在El capitan操作系統上的Safari 9中推送,並且它對於訂閱和交付工作正常,所以我不知道Safari 10的問題是什麼& Sierra OS。
這裏是webpush.js代碼:
const websitePushID = 'web.com.example';
const webServiceUrl = 'https://example.com';
var permissionData = {};
window.addEventListener('load', function() {
webPush.pushButton = $('.js-push-btn') || false;
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('/service-worker.js').then(webPush.initialiseState);
$('.js-push-btn').on('click', function() {
webPush.do();
});
} else {
if ('safari' in window && 'pushNotification' in window.safari) {
permissionData = window.safari.pushNotification.permission(websitePushID);
$('.js-push-btn').on('click', function() {
checkRemotePermission(permissionData);
});
}
}
});
var checkRemotePermission = function (permissionData) {
if (permissionData.permission === 'default') {
try {
console.log('default');
window.safari.pushNotification.requestPermission(
webServiceUrl,
websitePushID,
{},
checkRemotePermission
);
} catch (e) {
console.log(e);
}
}
else if (permissionData.permission === 'denied') {
console.log('denied');
}
else if (permissionData.permission === 'granted') {
console.log('granted');
}
};
DAT寫「默認」,之後「被拒絕」控制檯日誌