changeDeviceId static method

  1. @Deprecated('changeDeviceId is deprecated, use changeWithoutMerge of Countly.instance.deviceID if onServer = false and changeWithMerge if onServer = true, instead')
Future<String?> changeDeviceId(
  1. String newDeviceID,
  2. bool onServer
)

change the device ID if onServer is true, the old device ID is replaced with the new one and all data associated with the old device ID will be merged automatically. if onServer is false, the new device ID will be counted as a new device on the server. returns the error or success message

Implementation

@Deprecated('changeDeviceId is deprecated, use changeWithoutMerge of Countly.instance.deviceID if onServer = false and changeWithMerge if onServer = true, instead')
static Future<String?> changeDeviceId(String newDeviceID, bool onServer) async {
  log('changeDeviceId is deprecated, use ${onServer ? 'changeWithMerge' : 'changeWithoutMerge'} of Countly.instance.deviceID instead', logLevel: LogLevel.WARNING);
  if (!_instance._countlyState.isInitialized) {
    String message = '"initWithConfig" must be called before "changeDeviceId"';
    log('changeDeviceId, $message', logLevel: LogLevel.ERROR);
    return message;
  }
  log('Calling "changeDeviceId":[$newDeviceID] with onServer:[$onServer]');

  if (newDeviceID == Countly.temporaryDeviceID) {
    await _instance.deviceId.enableTemporaryIDMode();
  } else if (onServer) {
    await _instance.deviceId.changeWithMerge(newDeviceID);
  } else {
    await _instance.deviceId.changeWithoutMerge(newDeviceID);
  }
  return 'changeDeviceId Success';
}