PushManager
接口在
Push API
provides a way to receive notifications from third-party servers as well as request URLs for push notifications.
This interface is accessed via the
ServiceWorkerRegistration.pushManager
特性。
注意
: This interface replaces functionality previously offered by the obsolete
PushRegistrationManager
接口。
PushManager.supportedContentEncodings
Returns an array of supported content codings that can be used to encrypt the payload of a push message.
PushManager.getSubscription()
Promise
解析为
PushSubscription
object containing details of an existing subscription. If no existing subscription exists, this resolves to a
null
值。
PushManager.permissionState()
Promise
that resolves to the permission state of the current
PushManager
, which will be one of
'granted'
,
'denied'
,或
'prompt'
.
PushManager.subscribe()
Promise
解析为
PushSubscription
object containing details of a push subscription. A new push subscription is created if the current service worker does not have an existing subscription.
PushManager.hasPermission()
Promise
that resolves to the
PushPermissionStatus
of the requesting webapp, which will be one of
granted
,
denied
,或
default
. Replaced by
PushManager.permissionState()
.
PushManager.register()
PushManager.subscribe()
.
PushManager.registrations()
PushManager.getSubscription()
.
PushManager.unregister()
PushSubscription.unsubscribe()
方法。
this.onpush = function(event) {
console.log(event.data);
// From here we can write the data to IndexedDB, send it to any open
// windows, display a notification, etc.
}
navigator.serviceWorker.register('serviceworker.js').then(
function(serviceWorkerRegistration) {
serviceWorkerRegistration.pushManager.subscribe().then(
function(pushSubscription) {
console.log(pushSubscription.endpoint);
// The push subscription details needed by the application
// server are now available, and can be sent to it using,
// for example, an XMLHttpRequest.
}, function(error) {
// During development it often helps to log errors to the
// console. In a production environment it might make sense to
// also report information about errors back to the
// application server.
console.log(error);
}
);
});
| 规范 | 状态 | 注释 |
|---|---|---|
|
Push API
The definition of 'PushManager' in that specification. |
工作草案 | 初始定义。 |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
PushManager
|
Chrome 42 |
Edge
16
Disabled
|
Firefox
44
注意事项
|
IE 不支持 No | Opera 29 | Safari 不支持 No | WebView Android 不支持 No | Chrome Android 42 |
Firefox Android
48
注意事项
|
Opera Android 29 | Safari iOS 不支持 No | Samsung Internet Android 4.0 |
getSubscription
|
Chrome 42 |
Edge
16
Disabled
|
Firefox
44
注意事项
|
IE 不支持 No | Opera 29 | Safari 不支持 No | WebView Android 不支持 No | Chrome Android 42 |
Firefox Android
48
注意事项
|
Opera Android 29 | Safari iOS 不支持 No | Samsung Internet Android 4.0 |
hasPermission
|
Chrome 42 |
Edge
16
Disabled
|
Firefox
44
注意事项
|
IE 不支持 No | Opera 29 | Safari 不支持 No | WebView Android 不支持 No | Chrome Android 42 |
Firefox Android
48
注意事项
|
Opera Android 29 | Safari iOS 不支持 No | Samsung Internet Android 4.0 |
permissionState
|
Chrome 42 |
Edge
16
Disabled
|
Firefox
44
注意事项
|
IE 不支持 No | Opera 29 | Safari 不支持 No | WebView Android 不支持 No | Chrome Android 42 |
Firefox Android
48
注意事项
|
Opera Android 29 | Safari iOS 不支持 No | Samsung Internet Android 4.0 |
register
|
Chrome 42 |
Edge
16
Disabled
|
Firefox
44
注意事项
|
IE 不支持 No | Opera 29 | Safari 不支持 No | WebView Android 不支持 No | Chrome Android 42 |
Firefox Android
48
注意事项
|
Opera Android 29 | Safari iOS 不支持 No | Samsung Internet Android 4.0 |
registrations
|
Chrome 42 |
Edge
16
Disabled
|
Firefox
44
注意事项
|
IE 不支持 No | Opera 29 | Safari 不支持 No | WebView Android 不支持 No | Chrome Android 42 |
Firefox Android
48
注意事项
|
Opera Android 29 | Safari iOS 不支持 No | Samsung Internet Android 4.0 |
subscribe
|
Chrome
42
注意事项
|
Edge
16
Disabled
|
Firefox
44
注意事项
|
IE 不支持 No | Opera 29 | Safari 不支持 No | WebView Android 不支持 No | Chrome Android 42 |
Firefox Android
48
注意事项
|
Opera Android 29 | Safari iOS 不支持 No | Samsung Internet Android 4.0 |
supportedContentEncodings
|
Chrome 60 |
Edge
16
Disabled
|
Firefox
44
注意事项
|
IE 不支持 No | Opera 47 | Safari 不支持 No | WebView Android 不支持 No | Chrome Android 60 |
Firefox Android
48
注意事项
|
Opera Android 44 | Safari iOS 不支持 No | Samsung Internet Android 4.0 |
unregister
|
Chrome 42 |
Edge
16
Disabled
|
Firefox
44
注意事项
|
IE 不支持 No | Opera 29 | Safari 不支持 No | WebView Android 不支持 No | Chrome Android 42 |
Firefox Android
48
注意事项
|
Opera Android 29 | Safari iOS 不支持 No | Samsung Internet Android 4.0 |
完整支持
不支持
实验。期望将来行为有所改变。
见实现注意事项。
用户必须明确启用此特征。