ServiceWorkerの登録¶
RichFlyerのServiceWorker**(rf-serviceworker.js)**を登録し、受信した通知を表示できるようにします。
Webブラウザに搭載されている* Service Worker APIを利用します。
//Service Worker API
ServiceWorkerContainer.register(scriptURL, options)
パラメータ | 内容 |
---|---|
scriptURL | Service WorkerスクリプトのURL。rf-serviceworker.js を指定する |
options | Service Workerが有効となるスコープを指定(オプション) |
Example
if ("serviceWorker" in navigator) {
navigator.serviceWorker.register("rf-serviceworker.js").then(function(registration) {
console.log('Service worker registration succeeded:', registration);
}, function(error) {
console.log('Service worker registration failed:', error);
});
}
Info
rf_serviceworker.jsでは、通知受信時に表示されるダイアログをクリックしたときの処理が定義されています。
1番目のアクションボタンに設定したURLを表示します
アクションボタンを指定していない場合は、クリックしても何も実行されません。