0

我的工作Tizen耐磨獨立 Web應用程序,並希望整合火力地堡納入通知功能。我遵循使用JavaScript的firebase提供的所有步驟。但我無法獲得令牌,並結束了與下面的錯誤:FCM爲Tizen Werable Web應用程序

Failed to register a ServiceWorker: The URL protocol of the current origin 
('file://') is not supported." 
code: "messaging/failed-serviceworker-registration" 
message: "Messaging: We are unable to register the default service worker. 
Failed to register a ServiceWorker: The URL protocol of the current origin 
('file://') is not supported. (messaging/failed-serviceworker- 
registration)." 
stack: (...) 

我試圖

navigator.serviceWorker.register('/sw.js').then(function(registration) { 
console.log("success") 
firebase.messaging().useServiceWorker(registration) 
// Registration was successful 
console.log('ServiceWorker registration successful with scope: ',registration.scope); 
// registration.pushManager.subscribe({ 
console.log('Registration was successful1'); 
// userVisibleOnly: true 
}).then(function(sub) { 
    console.log('endpoint:', sub.endpoint); 
}).catch(function(e) { 
    console.log('Registration Failed',e); 
}); 

但無法得到它的工作。請讓我知道FCM是否提供了對Tizen Web應用程序的支持,因爲我已經看到FCM提供者爲Android,iOS和Javascript提供了訪問權限。但是我沒有看到對Tizen Web應用程序(可穿戴混合應用程序)的支持。

回答

0

Tizen Web應用程序不支持服務人員。 FCM JavaScript API需要服務工作者支持。

你可以試試這個簡單的代碼片段來檢查服務人員的支持。

if ('serviceWorker' in navigator) 
    alert('Service worker is Supported'); 
else 
    alert('Service worker is not Supported'); 

我試着在Firefox的代碼片段,鉻 (快捷鍵:開發者工具>控制檯>粘貼代碼>輸入)。

兩者都支持服務人員。但是當我在Tizen Web應用程序的js文件中添加這個代碼塊時,它會提醒「不支持」。

在Google開發人員註冊服務工作者的代碼示例在註冊之前首先還包括此檢查服務工作者API可用性。

Register a service worker

而關於本地移動環境,而不是網絡,FCM支持Android和iOS的原生環境,但不是Tizen本地。

相關問題