I am using AWS Mobile HUD with AWS SNS and am running into problems.
What works / was done already
- sucessfully created p12 universal certificate
- resources on AWS SNS created sucessfully by Mobile HUD
- topic created sucessfully by Mobile HUD
- integrated code into project
- integrated plist
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)
- Build config is DEBUG
- Logged platformARN is RELEASE and not DEBUG
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 ;)
2 Answers
Answers 1
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
Answers 2
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.
0 comments:
Post a Comment