5

I am trying to integrate AWS push notification service with IOS platform but it gives me unregistered or expired token error on sending notification from console.

I have registered device through amazon API which shows active status. Followed all steps for creating SSL certificates, setting up AWS SDKs, tried generating different certificates of production and sandbox too.

var pinpoint: AWSPinpoint?

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        
        registerForPushNotifications()
        
        /** start code copy **/
        // Create AWSMobileClient to connect with AWS
        AWSMobileClient.sharedInstance().initialize { (userState, error) in
            if let error = error {
                print("Error initializing AWSMobileClient: \(error.localizedDescription)")
            } else if let userState = userState {
                print("AWSMobileClient initialized. Current UserState: \(userState.rawValue)")
            }
        }
        
        // Initialize Pinpoint
        let pinpointConfiguration = AWSPinpointConfiguration.defaultPinpointConfiguration(launchOptions: launchOptions)
        pinpoint = AWSPinpoint(configuration: pinpointConfiguration)
        /** end code copy **/
        
        
        
        
        return true
    }

//FOR REGISTERING PUSH NOTIFICATIONS
  func registerForPushNotifications() {
        UNUserNotificationCenter.current().delegate = self
        UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound, .badge]) {
            (granted, error) in
            print("Permission granted: \(granted)")
            // 1. Check if permission granted
            guard granted else { return }
            // 2. Attempt registration for remote notifications on the main thread
            DispatchQueue.main.async {
                UIApplication.shared.registerForRemoteNotifications()
            }
        }
    }

//GENERATED TOKEN
    pinpoint!.notificationManager.interceptDidRegisterForRemoteNotifications(
            withDeviceToken: deviceToken)
        
        let deviceToken = deviceToken.map { String(format: "%02.2hhx", $0) }.joined()
        print("Token: \(deviceToken)")

After following all steps I get unregistered or expired token error.

Request Id 640 : {"errorMessage":"Unregistered or expired token","channelType":"APNS","pushProviderStatusCode":"400","pushProviderError":"BadDeviceToken","pushProviderResponse":"{"reason":"BadDeviceToken"}"}

2
  • 2
    I am having the same issue as well, have you figured out how to fix this? Aug 3, 2019 at 23:17
  • Hi, I am having the same issue but its happening on Android as I did not try on IOS. AWS Push notification (with firebase) is working but after sometime when app is idle on background, i come with same error "Unregistered or expired token". did anyone find the solution?? Thanks
    – Munish
    Mar 9, 2021 at 22:39

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.