2022-07-12 08:38:49 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								# pushNotifications
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								Process: [Main ](../glossary.md#main-process )
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								>  Register for and receive notifications from remote push notification services
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								For example, when registering for push notifications via Apple push notification services (APNS):
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-11-20 23:50:08 -08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								```js
							 
						 
					
						
							
								
									
										
										
										
											2022-07-12 08:38:49 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								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
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								The `pushNotification`  module emits the following events:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								#### Event: 'received-apns-notification' _macOS_
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								Returns:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-02-07 22:43:29 -08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								*  `event`  Event
							 
						 
					
						
							
								
									
										
										
										
											2024-03-25 03:19:44 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								*  `userInfo`  Record\<String, any\>
							 
						 
					
						
							
								
									
										
										
										
											2022-07-12 08:38:49 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								Emitted when the app receives a remote notification while running.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								See: https://developer.apple.com/documentation/appkit/nsapplicationdelegate/1428430-application?language=objc
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								## Methods
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								The `pushNotification`  module has the following methods:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								### `pushNotifications.registerForAPNSNotifications()` _macOS_
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								Returns `Promise<string>` 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-03-20 07:25:54 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								Registers the app with Apple Push Notification service (APNS) to receive [Badge, Sound, and Alert ](https://developer.apple.com/documentation/appkit/nsremotenotificationtype?language=objc ) 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.
							 
						 
					
						
							
								
									
										
										
										
											2022-07-12 08:38:49 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								See: https://developer.apple.com/documentation/appkit/nsapplication/1428476-registerforremotenotificationtyp?language=objc
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								### `pushNotifications.unregisterForAPNSNotifications()` _macOS_
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								Unregisters the app from notifications received from APNS.
							 
						 
					
						
							
								
									
										
										
										
											2025-03-20 07:57:50 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								Apps unregistered through this method can always reregister.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-07-12 08:38:49 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								See: https://developer.apple.com/documentation/appkit/nsapplication/1428747-unregisterforremotenotifications?language=objc