Device Registration
In this guide we will dive deeper into how you should handle the device registration. By default, when you launch()
Notificare, the device will be registered as a non-push device.
When a successful device registration takes place, we will emit an event. You can receive those events by listening to the Notificare.onDeviceRegistered
stream.
Notificare.onDeviceRegistered((device) => {
});
You can also check the details of the currently registered device.
const device = await Notificare.device().getCurrentDevice();
The onReady
stream will also be called when all Notificare modules has been launched, including a successful device registration.
Additionally, you can verify whether Notificare is ready at any point by calling Notificare.isReady
.
Assign a user to a device
By default, a device is registered as an anonymous user. However, there will be situations where simply registering the device as an anonymous user is not what you want. For example, if you authenticate your users, you will want to assign user information to the registered device as shown below.
await Notificare.device().updateUser('7f42bedc-d74b-4c64-a5cf-76bcc5130b05', 'John Doe');
After that, the device will remain registered with that userId
/userName
until you explicitly set the user as anonymous. Depending on the way you authenticate users, you might want to check the logged-in state on launch (in the onReady) and change it if necessary. Forcing registration as anonymous can be best achieved by setting userId
and userName
to null
.
await Notificare.device().updateUser(null, null);
Override Device Language
By default, we will automatically collect the language and region of a device based on the Locale of the device. For most cases this will be enough but for those cases where you would like to override the device language and region combination to a strict selection of languages, you can do so by invoking the following method:
await Notificare.device().updatePreferredLanguage('en-US');
Eventually, you can always retrieve the preferred language by calling the following method:
const language = await Notificare.device().getPreferredLanguage();
Do Not Disturb
Each device registered with Notificare can be configured to specify a period of time during the day when it should not receive notifications. You can use this functionality in your app settings to allow the user to provide a time range where messages will not be displayed in the lock screen or notification center. Please note that if you are using our inbox functionality these message will still be there.
To retrieve a device's DnD preferences use the following method:
const dnd = await Notificare.device().fetchDoNotDisturb();
You can update the DnD values for a device, using the following method:
await Notificare.device().updateDoNotDisturb(dnd);
Finally, you will probably also need to eventually clear the Do Not Disturb period. To do that, simply use the method below:
await Notificare.device().clearDoNotDisturb();