Skip to main content

pushNotifications

进程:主进程

🌐 Process: Main

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

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

🌐 For example, when registering for push notifications via Apple push notification services (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
})

事件

🌐 Events

pushNotification 模块会触发以下事件:

🌐 The pushNotification module emits the following events:

Event: 'received-apns-notification' macOS

返回:

🌐 Returns:

  • event 活动
  • 'userInfo'唱片<String, any>

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

🌐 Emitted when the app receives a remote notification while running. See: https://developer.apple.com/documentation/appkit/nsapplicationdelegate/1428430-application?language=objc

方法

🌐 Methods

pushNotification 模块具有以下方法:

🌐 The pushNotification module has the following methods:

pushNotifications.registerForAPNSNotifications() macOS

返回 Promise<string>

🌐 Returns Promise<string>

将应用注册到 Apple 推送通知服务 (APNS),以接收 徽章、声音和提醒 通知。如果注册成功,Promise 将会以 APNS 设备令牌为结果被解决。否则,Promise 将因错误信息而被拒绝。 查看: https://developer.apple.com/documentation/appkit/nsapplication/1428476-registerforremotenotificationtyp?language=objc

🌐 Registers the app with Apple Push Notification service (APNS) to receive Badge, Sound, and Alert notifications. If registration is successful, the promise will be resolved with the APNS device token. Otherwise, the promise will be rejected with an error message. See: https://developer.apple.com/documentation/appkit/nsapplication/1428476-registerforremotenotificationtyp?language=objc

pushNotifications.unregisterForAPNSNotifications() macOS

从从 APNS 收到的通知中取消注册应用。

🌐 Unregisters the app from notifications received from APNS.

通过此方法取消注册的应用始终可以重新注册。

🌐 Apps unregistered through this method can always reregister.

查看:https://developer.apple.com/documentation/appkit/nsapplication/1428747-unregisterforremotenotifications?language=objc

🌐 See: https://developer.apple.com/documentation/appkit/nsapplication/1428747-unregisterforremotenotifications?language=objc