SwPush

Subscribe and listen to push notifications from the Service Worker.

      
      class SwPush {
  messages: Observable<object>
  notificationClicks: Observable<{...}
  subscription: Observable<PushSubscription | null>
  isEnabled: boolean
  requestSubscription(options: { serverPublicKey: string; }): Promise<PushSubscription>
  unsubscribe(): Promise<void>
}
    

属性

属性说明
messages: Observable<object> 只读

Emits the payloads of the received push notification messages.

notificationClicks: Observable<{ action: string; notification: NotificationOptions & { title: string; }; }> 只读

Emits the payloads of the received push notification messages as well as the action the user interacted with. If no action was used the action property will be an empty string ''.

Note that the notification property is not a Notification object but rather a NotificationOptions object that also includes the title of the Notification object.

subscription: Observable<PushSubscription | null> 只读

Emits the currently active PushSubscription associated to the Service Worker registration or null if there is no subscription.

isEnabled: boolean 只读

True if the Service Worker is enabled (supported by the browser and enabled via ServiceWorkerModule).

方法

requestSubscription(options: { serverPublicKey: string; }): Promise<PushSubscription>
      
      requestSubscription(options: { serverPublicKey: string; }): Promise<PushSubscription>
    
参数
options object
返回值

Promise<PushSubscription>

unsubscribe(): Promise<void>
      
      unsubscribe(): Promise<void>
    
参数

没有参数。

返回值

Promise<void>