Skip to content

Instantly share code, notes, and snippets.

@codelynx
Created June 10, 2024 00:36
Show Gist options
  • Save codelynx/7458a592aaf108e9f518f726d7645d8d to your computer and use it in GitHub Desktop.
Save codelynx/7458a592aaf108e9f518f726d7645d8d to your computer and use it in GitHub Desktop.
Register Apple's push notification device token to Amazon AWS SNS
/*
Using AWS-SDK-SWIFT to register push notification deveice token
https://github.com/awslabs/aws-sdk-swift
*/
// import some others
import AWSSNS
func createPlatformEndpoint(token: String, region: String, accessKey: String, secret: String, platformApplicationArn: String) async {
do {
let credentialsResolver = try StaticAWSCredentialIdentityResolver(
.init(accessKey: accessKey, secret: secret)
)
let config = try await SNSClient.SNSClientConfiguration(
awsCredentialIdentityResolver: credentialsResolver, region: region
)
let snsClient = SNSClient(config: config)
let input = CreatePlatformEndpointInput(attributes: [:], customUserData: nil, platformApplicationArn: platformApplicationArn, token: token)
let endpointArn = try await snsClient.createPlatformEndpoint(input: input)
print("endpointArn=", endpointArn)
}
catch {
print("\(error)")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment