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"}"}