src/Mcfedr/AwsPushBundle/Service/Devices.php
public function registerDevice(string $deviceId, string $platform, ?string $userData = null): string
    {
        if (!isset($this->arns[$platform])) {
            throw new PlatformNotConfiguredException("There is no configured ARN for $platform");
        }

        try {
            $args = [
                'PlatformApplicationArn' => $this->arns[$platform],
                'Token' => $deviceId,
                'Attributes' => [
                    'Enabled' => 'true',
                ],
            ];

            if ($userData) {
                $args['CustomUserData'] = $userData;
            }

            $res = $this->sns->createPlatformEndpoint($args);
        } catch (SnsException $e) {
            preg_match('/Endpoint (.+?) already/', $e->getMessage(), $matches);
            if (isset($matches[1])) {
                $this->sns->setEndpointAttributes(
                    [
                        'EndpointArn' => $matches[1],
                        'Attributes' => [
                            'Enabled' => 'true',
                        ],
                    ]
                );

                return $matches[1];
            } else {
                throw $e;
            }
        }

        return $res['EndpointArn'];
    }
public function registerDevice(string $deviceId, string $platform, ?string $userData = null): string
    {
        if (!isset($this->arns[$platform])) {
            throw new PlatformNotConfiguredException("There is no configured ARN for $platform");
        }

        try {
            $args = [
                'PlatformApplicationArn' => $this->arns[$platform],
                'Token' => $deviceId,
                'Attributes' => [
                    'Enabled' => 'true',
                ],
            ];

            if ($userData) {
                $args['CustomUserData'] = $userData;
            }

            $res = $this->sns->createPlatformEndpoint($args);
        } catch (SnsException $e) {
            preg_match('/Endpoint (.+?) already/', $e->getMessage(), $matches);
            if (isset($matches[1])) {
                $this->sns->setEndpointAttributes(
                    [
                        'EndpointArn' => $matches[1],
                        'Attributes' => [
                            'Enabled' => 'true',
                        ],
                    ]
                );

                return $matches[1];
            } else {
                throw $e;
            }
        }

        return $res['EndpointArn'];
    }
Register a device token.

@param string $deviceId device token
@param string $platform platform on which to register
@param string $userData Arbitrary user data to associate with the endpoint

@return string the endpoint ARN for this device

@throws PlatformNotConfiguredException
@throws \Exception