2015-11-25 85 views
2

訂閱時我有註冊ID,但是當我收到推送通知時,我無法弄清楚如何獲取它在服務工作者文件中?如何在ServiceWorker中的推送事件中獲取註冊ID?

client.js

pushManager.subscribe({ userVisibleOnly: true }).then(({ endpoint }) => { 
    const registrationId = endpoint.split('https://android.googleapis.com/gcm/send/')[1]; 
    // How do I get this registrationId in service-worker.js below? 
}); 

服務worker.js

self.addEventListener('push', event => { 
    // I'd like to make a request to server to get the notification data, but I need the registrationId for that. How do I get registration id here? 
}); 

回答