sendDeviceSignature static method

Future<String?> sendDeviceSignature(
  1. String screenName, {
  2. String? userId,
})

Implementation

static Future<String?> sendDeviceSignature(
    String screenName, {
      String? userId,
    }) async {
  try {
    final args = <String, dynamic>{
      "screenName": screenName,
    };

    if (userId != null && userId.isNotEmpty) {
      args["userId"] = userId;
    }

    final result = await _channel
        .invokeMethod(
      "sendDeviceSignature",
      args,
    )
        .timeout(const Duration(seconds: 30), onTimeout: () => null);

    latestError = null;

    // timeout case
    if (result == null) {
      latestError = const ShieldError(
        "0",
        "sendDeviceSignature timed out or failed",
      );
      return null;
    }

    // iOS old SDK → bool
    if (result is bool) {
      if (!result) {
        latestError = const ShieldError("0", "sendDeviceSignature failed");
        return null;
      }
      return await sessionId;
    }

    return result?.toString();
  } on PlatformException catch (e, s) {
    _internalLog("sendDeviceSignature failed", e, s);
    latestError = ShieldError(
      e.code,
      e.message ?? e.details?.toString() ?? "Unknown error",
      exception: e.details?.toString(),
    );
    return null;
  } catch (e, s) {
    _internalLog("sendDeviceSignature failed", e, s);
    latestError = ShieldError(
      "0",
      e.toString().isNotEmpty
          ? e.toString()
          : (s.toString().isNotEmpty ? s.toString() : "Unknown error"),
    );
    return null;
  }
}