Push Notifications
The Amazon Connect Customer Profiles APIs let your application send profile information for the current user and manage that person's registered push devices. Devices are stored separately from the Customer Profile, in a DynamoDB device store, associated by principalId, rather than embedded inside the profile. Requests are signed with Signature Version 4 using Amazon Cognito identity pool credentials, and your backend derives the profile identity from the signed request.
These APIs are provided by AmplifyConnectClient, a standalone client distributed with the Amplify Swift libraries. It exposes three methods: identifyUser, registerDevice, and removeDevice.
Install the library
Add AmplifyConnectClient to your project using Swift Package Manager. In Xcode, go to File > Add Package Dependencies and enter the repository URL for the Amplify Swift SDK, then select the AmplifyConnectClient product.
Create the client
The endpoint and Region that your backend deployed are read from the notifications.amazon_connect section of amplify_outputs.json in your main bundle. Create the client with a credentials provider that resolves credentials from Amplify Auth:
import Amplifyimport AmplifyConnectClientimport AmplifyFoundationimport AWSCognitoAuthPluginimport AWSPluginsCore
let configuration = try ConnectClientConfiguration()
let client = AmplifyConnectClient( configuration: configuration, credentialsProvider: CognitoConnectCredentialsProvider())The credentials provider bridges the Amplify Auth session to the AWSCredentialsProvider protocol from the Amplify Swift foundation packages:
struct CognitoConnectCredentialsProvider: AmplifyFoundation.AWSCredentialsProvider { func resolve() async throws -> AmplifyFoundation.AWSCredentials { let session = try await Amplify.Auth.fetchAuthSession() guard let provider = session as? AuthAWSCredentialsProvider else { throw ConnectError.credentials( "Auth session does not vend AWS credentials.", "Configure Amplify Auth with a Cognito identity pool." ) } let credentials = try provider.getAWSCredentials().get()
if let temporary = credentials as? AWSPluginsCore.AWSTemporaryCredentials { return TemporaryCredentials( accessKeyId: temporary.accessKeyId, secretAccessKey: temporary.secretAccessKey, sessionToken: temporary.sessionToken, expiration: temporary.expiration ) } return StaticCredentials( accessKeyId: credentials.accessKeyId, secretAccessKey: credentials.secretAccessKey ) }}
struct StaticCredentials: AmplifyFoundation.AWSCredentials { let accessKeyId: String let secretAccessKey: String}
struct TemporaryCredentials: AmplifyFoundation.AWSTemporaryCredentials { let accessKeyId: String let secretAccessKey: String let sessionToken: String let expiration: Date}You can also construct the configuration manually with ConnectClientConfiguration(region:endpoint:). The endpoint must be an https:// URL.