2017-08-07 86 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了解更多信息。