2017-08-07 53 views

回答

1

您可能想檢查有關Web Push Notifications的文檔。推送基於服務人員,因爲服務人員在後臺操作。這意味着唯一的時間碼是針對推送通知運行的(換句話說,電池使用的唯一時間)是用戶通過單擊或關閉通知與通知進行交互的時間碼。如果您不熟悉它們,請查看service worker introduction

通過服務人員註冊,您可以在註冊對象上調用showNotification。

serviceWorkerRegistration.showNotification(title, options); 

title參數顯示爲通知中的標題。 options參數是設置通知的其他屬性的對象字面值。典型的選項對象如下所示:

{ 
    "body": "Did you make a $1,000,000 purchase at Dr. Evil...", 
    "icon": "images/ccard.png", 
    "vibrate": [200, 100, 200, 100, 200, 100, 400], 
    "tag": "request", 
    "actions": [ 
    { "action": "yes", "title": "Yes", "icon": "images/yes.png" }, 
    { "action": "no", "title": "No", "icon": "images/no.png" } 
    ] 
} 

請檢查此documentation瞭解更多信息。