The Push Notifications API provides access to native Azure push notifications.
npm install azure-push-notificationsThe Push Notifications API provides access to native push notifications.
``bash`
npm i azure-push-notifications
npx cap sync
`js`
import {
AzurePushNotifications,
AzurePushNotificationSchema,
PushNotificationActionPerformed,
PushNotificationToken,
} from 'azure-push-notifications';
`js
AzurePushNotifications.requestPermissions().then((result) => {
AzurePushNotifications.register({
notificationHubName: '
connectionString:
'
deviceTag: '
}).then(() => {
AzurePushNotifications.addListener(
'registration',
(token: PushNotificationToken) => {
alert('Push registration success, token: ' + token.value);
}
);
});
});
`
`js
AzurePushNotifications.addListener(
'registrationError',
(error: any) => {
alert('Error on registration: ' + JSON.stringify(error));
}
);
AzurePushNotifications.addListener(
'pushNotificationReceived',
(notification: AzurePushNotificationSchema) => {
alert('Push received: ' + JSON.stringify(notification));
}
);
AzurePushNotifications.addListener(
'pushNotificationActionPerformed',
(notification: PushNotificationActionPerformed) => {
alert('Push action performed: ' + JSON.stringify(notification));
}
);
``