Updated on 20. December 2023 by Jan Bunk
The basic concept on how you can send push notifications to individual users of your app is as follows:
getNotificationToken
which returns the app instance's push notification token.executeWhenAppReady()
function of our app helper script. It ensures that your website doesn't try to interact with the app before it's ready or when your website is loaded using a regular browser (ReferenceError, function is not defined). This is the old implementation used in apps created/updated before August 2021.
You need to define the receivePushNotificationToken function on your website so that it can be called by the app. You can do so as follows:
<script>
// this function automatically gets called by the app
function receivePushNotificationToken(token) {
// store the token (or whatever you want to do with it)
}
</script>
Things to keep in mind:
When you want to get an app instance's push notification token, simply call the getNotificationToken
function.
<script>
try {
var token = (await getNotificationToken())["token"];
}
catch (e) {
// Can occur if:
// - the app couldn't connect to the native code. Should be very unlikely.
// - the app couldn't get the push notification token, maybe because of connection issues. Should be very unlikely.
// - push notifications are not included in your current plan
console.log(e);
}
</script>
Things to keep in mind:
Get your app-specific API key from your app dashboard.
Send your API key as a query in the URL and the request body in the JSON format.
Here's a list of related developer documentation about push notifications:
And here are some more (non-developer) articles related to push notifications: