Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS Mobile HUD AWS SNS pushManagerDidRegister but endpoint not created

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 ;)

like image 579
Sebastian Flückiger Avatar asked May 31 '17 16:05

Sebastian Flückiger


2 Answers

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

like image 62
Hady Nourallah Avatar answered Nov 12 '22 21:11

Hady Nourallah


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.

like image 36
Sebastian Flückiger Avatar answered Nov 12 '22 21:11

Sebastian Flückiger



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!