Aller au contenu principal

notifications Push

Process: Main

S'inscrire et recevoir les notifications des services de notification push à distance

Par exemple, lors de l'enregistrement des notifications push via les services de notification push d'Apple (APNS):

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

pushNotifications.registerForAPNSNotifications().then((token) => {
// transmet le jeton vers votre serveur de notification distant
})

pushNotifications.on('received-apns-notification', (event, userInfo) => {
// génère un nouvel objet Notification avec les champs de userInfo pertinents
})

Événements​

Le module pushNotification émet les événements suivants :

Événement : 'received-apns-notification' macOS​

Retourne :

  • event Event
  • userInfo Record<String, any>

Émis lorsque l'application reçoit une notification à distance pendant son exécution. Voir : https://developer.apple.com/documentation/appkit/nsapplicationdelegate/1428430-application?language=objc (an)

Méthodes​

Le module pushNotification dispose des méthodes suivantes :

pushNotifications.registerForAPNSNotifications() macOS​

Retourne Promise<string>

Enregistre l'application avec le service de notification Push d'Apple (APNS) pour recevoir des notifications Badge, Sound, et Alert. Si l'inscription réussit, la promesse sera résolue avec le jeton de l'appareil APNS. Sinon, la promesse sera rejetée avec un message d'erreur. Voir : https://developer.apple.com/documentation/appkit/nsapplication/1428476-registerforremotenotificationtyp?language=objc (an)

pushNotifications.unregisterForAPNSNotifications() macOS​

Supprime l'enregistrement de l'application pour les notifications en provenance de APNS. Voir : https://developer.apple.com/documentation/appkit/nsapplication/1428747-unregisterforremotenotifications?language=objc (an)