I am using AWS Mobile HUD with AWS SNS and am running into problems.
What works / was done already
the following code should register the app (device) with AWS SNS:
pushManager = AWSPushManager(forKey: ServiceKey)
pushManager?.delegate = self
pushManager?.registerForPushNotifications()
and - greatly enough func pushManagerDidRegister(_ pushManager: AWSPushManager)
is called, indicating success. My func pushManagerDidRegister(_ pushManager: AWSPushManager)
looks as fo
func pushManagerDidRegister(_ pushManager: AWSPushManager) {
print("Successfully enabled Push Notifications on platform: \(pushManager.platformARN)")
// Subscribe the first topic among the configured topics (all-device topic)
if let defaultSubscribeTopic = pushManager.topicARNs?.first {
let topic = pushManager.topic(forTopicARN: defaultSubscribeTopic)
topic.subscribe()
}
}
log output:
Successfully enabled Push Notifications on platform: Optional("arn:aws:sns:eu-central-1:00000000:app/APNS/appname_MOBILEHUD_12345678")
but: on AWS SNS resource no endpoint is created in this application / platformARN
Interesting facts (maybe the reason)
edit
: After playing around with different swift compiler flags I managed to set the environment correclty. Now i get logging that the registration was successfull on the Sandbox Environment. But: still no endpoint created on AWS SNS.
any ideas on how i could proceed? I tried for 2 days now including recertification, rebuilding AWS, endless logging ;)
so I looked for the issue in docs and their github.
What I noticed that they are using AWSSNSCreatePlatformEndpointInput
which you don't have, also you have to get device token from func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData)
and register it.
anyway it should be something like this
func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) {
let deviceTokenString = "\(deviceToken)".stringByTrimmingCharactersInSet(NSCharacterSet(charactersInString:"<>"))
.stringByReplacingOccurrencesOfString(" ", withString: "")
print("deviceTokenString: \(deviceTokenString)")
NSUserDefaults.standardUserDefaults().setObject(deviceTokenString, forKey: "deviceToken")
mainViewController()?.displayDeviceInfo()
let sns = AWSSNS.defaultSNS()
let request = AWSSNSCreatePlatformEndpointInput()
request.token = deviceTokenString
request.platformApplicationArn = SNSPlatformApplicationArn
sns.createPlatformEndpoint(request).continueWith(executor: AWSExecutor.mainThreadExecutor(), block: { (task: AWSTask!) -> AnyObject! in
if task.error != nil {
print("Error: \(task.error)")
} else {
let createEndpointResponse = task.result as! AWSSNSCreateEndpointResponse
print("endpointArn: \(createEndpointResponse.endpointArn)")
NSUserDefaults.standardUserDefaults().setObject(createEndpointResponse.endpointArn, forKey: "endpointArn")
self.mainViewController()?.displayDeviceInfo()
}
return nil
})
}
please, update me what happened and good luck
I found the answer here: AWS push notification service integration error
The issue was with missing privileges on AWS Mobile HUB. Sadly no sensible error was created ;)
Adding the policy AmazonSNSFullAccess solved it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With