registerDevice method

Future<RegisterDeviceResponse> registerDevice({
  1. required String identityId,
  2. required String identityPoolId,
  3. required Platform platform,
  4. required String token,
})

Registers a device to receive push sync notifications.

This API can only be called with temporary credentials provided by Cognito Identity. You cannot call this API with developer credentials.

May throw NotAuthorizedException. May throw InvalidParameterException. May throw ResourceNotFoundException. May throw InternalErrorException. May throw InvalidConfigurationException. May throw TooManyRequestsException.

Parameter identityId : The unique ID for this identity.

Parameter identityPoolId : A name-spaced GUID (for example, us-east-1:23EC4050-6AEA-7089-A2DD-08002EXAMPLE) created by Amazon Cognito. Here, the ID of the pool that the identity belongs to.

Parameter platform : The SNS platform type (e.g. GCM, SDM, APNS, APNS_SANDBOX).

Parameter token : The push token.

Implementation

Future<RegisterDeviceResponse> registerDevice({
  required String identityId,
  required String identityPoolId,
  required Platform platform,
  required String token,
}) async {
  ArgumentError.checkNotNull(identityId, 'identityId');
  _s.validateStringLength(
    'identityId',
    identityId,
    1,
    55,
    isRequired: true,
  );
  ArgumentError.checkNotNull(identityPoolId, 'identityPoolId');
  _s.validateStringLength(
    'identityPoolId',
    identityPoolId,
    1,
    55,
    isRequired: true,
  );
  ArgumentError.checkNotNull(platform, 'platform');
  ArgumentError.checkNotNull(token, 'token');
  final $payload = <String, dynamic>{
    'Platform': platform.toValue(),
    'Token': token,
  };
  final response = await _protocol.send(
    payload: $payload,
    method: 'POST',
    requestUri:
        '/identitypools/${Uri.encodeComponent(identityPoolId)}/identity/${Uri.encodeComponent(identityId)}/device',
    exceptionFnMap: _exceptionFns,
  );
  return RegisterDeviceResponse.fromJson(response);
}