registerDevice static method
Register a device token.
@param token: the token for this device, typically coming from the onToken callback.
@returns A future that completes once the registration is successful.
Implementation
static Future<void> registerDevice(String token) async {
_log('π [MPush API] registerDevice called with token ${_redact(token)}');
Map<String, String> apiParameters = {};
apiParameters.addAll(await _defaultParameters());
apiParameters['token'] = token;
String apiName = 'api/tokens';
var requestBody = json.encode(apiParameters);
_log('π [MPush API] registerDevice posting for device');
Map<String, String> headers = _defaultHeaders(contentTypeJson: true);
var uri = Uri.https(_endpoint, apiName);
_log('π [MPush API] registerDevice URL: $uri');
http.Response response = await http.post(
uri,
headers: headers,
body: requestBody,
);
_log(
'π [MPush API] registerDevice response: ${response.statusCode} - ${response.body}');
_checkResponse(response.body);
}