跳至主要内容

pushNotifications

进程: 主进程

注册并接收来自远程推送通知服务的通知

例如,通过 Apple 推送通知服务 (APNS) 注册推送通知

const { pushNotifications, Notification } = require('electron')

pushNotifications.registerForAPNSNotifications().then((token) => {
// forward token to your remote notification server
})

pushNotifications.on('received-apns-notification', (event, userInfo) => {
// generate a new Notification object with the relevant userInfo fields
})

事件

pushNotification 模块发出以下事件

事件: 'received-apns-notification' macOS

返回值

  • event 事件
  • userInfo Record<String, any>

当应用程序运行时接收远程通知时发出。参见: https://developer.apple.com/documentation/appkit/nsapplicationdelegate/1428430-application?language=objc

方法

pushNotification 模块具有以下方法

pushNotifications.registerForAPNSNotifications() macOS

返回值 Promise<string>

将应用程序注册到 Apple 推送通知服务 (APNS),以接收 徽章、声音和提醒 通知。如果注册成功,承诺将用 APNS 设备令牌解析。否则,承诺将被错误消息拒绝。参见: https://developer.apple.com/documentation/appkit/nsapplication/1428476-registerforremotenotificationtyp?language=objc

pushNotifications.unregisterForAPNSNotifications() macOS

取消注册应用程序,使其不再接收来自 APNS 的通知。参见: https://developer.apple.com/documentation/appkit/nsapplication/1428747-unregisterforremotenotifications?language=objc