2017-02-13 6 views
1

すべてのWebブラウザとモバイルブラウザでHTML5プッシュ通知が機能しなくなりました。現時点では、私は次のコードを持っている:私は試してみて、Chromeを使用して、私のアンドロイド携帯電話上でコードを使用する場合すべてのWebブラウザとモバイルブラウザでHTML5プッシュ通知が機能するようにするにはどうすればよいですか?

<html> 
<head> 
<script> 
document.addEventListener('DOMContentLoaded', function() { 
    if (Notification.permission !== "granted") 
    Notification.requestPermission(); 
}); 

function notifyMe() { 
    if (!Notification) { 
    alert('Desktop notifications not available in your browser.'); 
    return; 
    } 

    if (Notification.permission !== "granted") 
    Notification.requestPermission(); 
    else { 
    var notification = new Notification('Notification title', { 
     icon: 'https://www.google.co.uk/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png', 
     body: "Hey there! You've been notified!", 
    }); 

    notification.onclick = function() { 
     window.open("https://www.google.com");  
    }; 

    } 

} 
</script> 
</head> 
<body> 

<a href="javascript://" onclick="setTimeout(function(){ notifyMe(); }, 1500);" style="font-size:50px;background:#000;color:#fff;">Test nofitications (Will load in 1.5 seconds)</a> 

</body> 
</html> 

、それは許可を求めたが、実際の通知が動作しません。

アイデア?

編集:

はありません成功し、次の試してみました:

http://www.girliemac.com/html5-notifications-webOS-style/ 
http://elfoxero.github.io/html5notifications/ 
http://codepen.io/imprakash/pen/ZYLayY 
https://www.daftlogic.com/sandbox-using-html5-notifications.htm 
https://davidwalsh.name/demo/notifications-api.php 
http://ttsvetko.github.io/HTML5-Desktop-Notifications/ 
http://jsfiddle.net/Semmel/kY3Cq/ 
https://gauntface.github.io/simple-push-demo/ 
https://github.com/alexgibson/notify.js/blob/master/example/index.html 
+0

あなたが試すことができますChrome dev Toolsを使用してデスクトップから携帯電話の動作をデバッグし、 'console'でエラーが発生していないかどうかを確認することができます。 –

答えて

1

通知のみプッシュイベントを経由してAndroid上でサービスワーカーで使用できるように変更しました。

あなたはサービスワーカーに次の操作を実行する必要がある代わりに、 new Notification()を使用して通知をすることはできませんプッシュイベントから

:プッシュ通知の詳細については

self.addEventListener('push', (event) => { 
    event.waitUntil(self.registration.showNotification('Title', { 
    body: 'Hello, World' 
    })); 
}); 

https://web-push-book.gauntface.com/

関連する問題