本文へスキップ

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 イベント
  • userInfo Record<String, any>

アプリが実行中にリモート通知を受信したときに発生します。参照: https://developer.apple.com/documentation/appkit/nsapplicationdelegate/1428430-application?language=objc

メソッド

pushNotificationモジュールには、以下のメソッドがあります。

pushNotifications.registerForAPNSNotifications() macOS

戻り値 Promise<string>

アプリをApple Push Notificationサービス(APNS)に登録して、バッジ、サウンド、アラート通知を受信します。登録が成功すると、プロミスはAPNSデバイストークンで解決されます。それ以外の場合は、エラーメッセージでプロミスが拒否されます。参照: 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