pushNotifications
进程:主进程
¥Process: Main
注册远程推送通知服务并接收来自远程推送通知服务的通知
¥Register for and receive notifications from remote push notification services
例如,当通过 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:
事件:'received-apns-notification' macOS
¥Event: 'received-apns-notification' macOS
返回:
¥Returns:
-
event
事件¥
event
Event -
userInfo
记录<字符串,任意>¥
userInfo
Record<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 收到的通知中取消注册应用。看:https://developer.apple.com/documentation/appkit/nsapplication/1428747-unregisterforremotenotifications?language=objc
¥Unregisters the app from notifications received from APNS. See: https://developer.apple.com/documentation/appkit/nsapplication/1428747-unregisterforremotenotifications?language=objc