Device Management
Subscribing your Device
To receive Push Notifications on iOS, Android and React Native, you first need to subscribe (ie. register your device token with DashX).
Simply use the subscribe()
method to save the current device as one of the contacts that belongs to the current identity.
To verify if the current device has been saved,
- Head to the User Management app
- Open either Users or Visitors
- Filter & locate the identity you are looking for, and click on their name to open up the Details side pane.
- Under the Related section, select Contacts as shown in the screenshot.
- iOS
- Android
- React Native
DashX.subscribe();
Android 13 introduced runtime permission for push notifications. So in your application code, based on the android version, you can check if this permission is granted by the user, and then call DashX's subscribe()
method. For example:
import android.os.Build
import com.dashx.sdk.utils.PermissionUtils
// ...
class SomeActivity : AppCompatActivity() {
private val postNotificationRequestCode = 1
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU) {
DashX.subscribe()
return
}
if (PermissionUtils.hasPermissions(this, android.Manifest.permission.POST_NOTIFICATIONS)) {
DashX.subscribe()
} else {
PermissionUtils.requestPermission(this, android.Manifest.permission.POST_NOTIFICATIONS, postNotificationRequestCode)
}
}
// ...
override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<out String>, grantResults: IntArray) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
if (requestCode == postNotificationRequestCode) {
if (grantResults.isNotEmpty() && grantResults.first() == PackageManager.PERMISSION_GRANTED) {
DashX.subscribe()
} else {
// This means user denied your request. It is left up to you to decide when do you want to prompt the user again.
// You just need to make sure that the user has granted the above permission before you call the `subscribe()` method.
}
}
}
// ...
import DashX from '@dashx/react-native';
DashX.subscribe();
Unsubscribing your Device
To stop receiving Push Notifications, simply use the unsubscribe()
method to unregister the current device token. This is useful when you have a Notification Preferences screen on your web or mobile app that allows the user to manually unsubscribe from Push Notifications.
If you have implemented the User Logout flow, you can just call reset()
which implicitly calls unsubscribe()
. This ensures that you do NOT continue sending push notifications to a device once the user has logged out, or is logged into another account in the same device.
If your user is offline, note that the device token will be unregistered, but the contact status may not reflect correctly on DashX.
- iOS
- Android
- React Native
DashX.unsubscribe();
DashX.unsubscribe();
import DashX from '@dashx/react-native';
DashX.unsubscribe();