unsetPushRegistration method
Unregisters a single mobile device, as one user can be connected to multiple mobile devices.
If the provider
and pushRegistrationId
parameters are not passed, it unregisters the default Firebase token
for Android, or the default Apns token for iOS, for this device.
If passing parameters to this function, both provider
and pushRegistrationId
must not be null
Implementation
Future<void> unsetPushRegistration({
Provider? provider,
String? pushRegistrationId,
}) async {
if ((provider == null && pushRegistrationId != null) ||
(provider != null && pushRegistrationId == null)) {
throw StateError('provider and pushRegistrationId must both be non-null');
}
// We check the completer first because _headlessWebView may be null because we haven't loaded the version asset yet.
if (!_completer.isCompleted) {
if (_me == null) {
throw StateError(
'The me property needs to be set for the Session object before calling unsetPushRegistration');
}
if (kDebugMode) {
print(
'📗 session unsetPushRegistration: !_completer.isCompleted, awaiting for _completer.future');
}
await _completer.future;
}
if (_headlessWebView == null) {
throw StateError(
'The unsetPushRegistration method cannot be called after destroying the session');
}
if (kDebugMode) {
print('📗 session unsetPushRegistration: Disabling push notifications');
}
if (provider == null && pushRegistrationId == null) {
_setOrUnsetPushRegistration(false);
} else {
_execute(
'session.unsetPushRegistration({provider: "${provider!.name}", pushRegistrationId: "$pushRegistrationId"});');
}
}