跳转至

pushNotifications

进程:主进程

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

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

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

pushNotifications.registerForAPNSNotifications().then((token) => {
  // 将 token 转发到你的远程通知服务器
})

pushNotifications.on('received-apns-notification', (event, userInfo) => {
  // 使用相关的 userInfo 字段生成一个新的 Notification 对象
})

事件

pushNotification 模块触发以下事件:

事件:'received-apns-notification' macOS

返回:

  • event Event
  • userInfo Record\<String, any>

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

方法

pushNotification 模块有以下方法:

pushNotifications.registerForAPNSNotifications() macOS

返回 Promise<string>

向 Apple 推送通知服务(APNS)注册应用,以接收 标记、声音和提醒 通知。如果注册成功,Promise 将以 APNS 设备令牌完成解析。否则,Promise 将带着错误消息被拒绝。 参见: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

本页原文 Markdown:在 AtomGit 查看·内容源自开源项目 el/electron