getNewToken method

Future<String> getNewToken(
  1. String token, {
  2. String? apnsToken,
})

Implementation

Future<String> getNewToken(String token, {String? apnsToken}) async {
  final body = json.encode(<String, dynamic>{
    "clientToken": token,
    if (apnsToken != null)
      "deviceSettings": [
        {"deviceToken": apnsToken, "transportKind": "Apns"}
      ]
  });
  print(body);
  try {
    var response = await http
        .post(Uri.parse('https://sub.pushed.ru/tokens'),
            headers: {"Content-Type": "application/json"}, body: body)
        .timeout(const Duration(seconds: 10),
            onTimeout: (() => throw Exception("TimeOut")));
    token = json.decode(response.body)["token"];
  } catch (e) {
    token = "";
  }
  return (token);
}