如何使用 AWS 推送通知服务修复未注册或过期的令牌错误

Ade*_*ani 5 push-notification amazon-web-services ios

我正在尝试将 AWS 推送通知服务与 IOS 平台集成,但从控制台发送通知时出现未注册或过期令牌错误。

我已通过亚马逊 API 注册了设备,该设备显示活动状态。遵循创建 SSL 证书、设置 AWS SDK 的所有步骤,也尝试生成不同的生产证书和沙箱证书。

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)")
Run Code Online (Sandbox Code Playgroud)

完成所有步骤后,我收到未注册或过期令牌错误。

请求 ID 640 : {"errorMessage":"未注册或过期的令牌","channelType":"APNS","pushProviderStatusCode":"400","pushProviderError":"BadDeviceToken","pushProviderResponse":"{"reason": “BadDeviceToken”}“}