跳至主要內容

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 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