跳转到主内容

pushNotifications

进程:主进程

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

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

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

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

pushNotifications.on('received-apns-notification', (event, userInfo) => {
// 通过相关用户信息字段生成一个新的通知对象
})

事件

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 Push 通知服务 (APNS) 以接收 Badge, Sound, and Alert 通知。 如果注册成功,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