2017-07-04 18 views
0

現在、私のウェブサイトにプッシュ通知を実装しようとしていますが、動的なタイトルとリンクを表示しようとしています。サービス作業とプッシュ通知

これあなたが見ることができるように私のサービスワーカーは現在

self.addEventListener('push', function(event) { 
    // console.log('[Service Worker] Push Received.'); 
    // console.log('[Service Worker] Push has this data: '); 

    const title = event.data.title; 
    const options = { 
     body: event.data.text(), 
    } 

    const notificationPromise = self.registration.showNotification(title, options); 
    event.waitUntil(notificationPromise); 
}); 

self.addEventListener('notificationclick', function(event) { 
    console.log('[Service Worker] Notification click Received.'); 

    event.notification.close(); 

    event.waitUntil(
     clients.openWindow('https://developers.google.com') 
    ); 
}) 

どのようなものか、現在のリンクがハードコーディングされたdevelopers.google.comリンクで、タイトルに戻り「未定義の」が

Screenshot of Notification

これらをペイロードに送信するために、ウェブサイトのバックエンドから何かする必要がありますか?

場合、それは私が、私はこれは実際にあなたがJSONオブジェクトからタイトルデータにアクセスしているかの問題であると考えていWeb Push Library for C#

答えて

1

を使用していますができます。

event.dataオブジェクトにjsonオブジェクトとしてアクセスするには、データオブジェクトに対してjson()メソッドを呼び出す必要があります。だからこのようなもの:

const title = event.data.json().title; 
関連する問題