ios - 如何使用 AWS 推送通知服务修复未注册或过期令牌错误
问题描述
我正在尝试将 AWS 推送通知服务与 IOS 平台集成,但它在从控制台发送通知时给了我未注册或过期的令牌错误。
我已经通过显示活动状态的亚马逊 API 注册了设备。遵循创建 SSL 证书、设置 AWS 开发工具包的所有步骤,并尝试生成不同的生产证书和沙盒证书。
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)")
完成所有步骤后,我得到未注册或过期的令牌错误。
请求 ID 640:{"errorMessage":"未注册或过期令牌","channelType":"APNS","pushProviderStatusCode":"400","pushProviderError":"BadDeviceToken","pushProviderResponse":"{"reason": "BadDeviceToken"}"}
解决方案
推荐阅读
- eslint - 导入``,ESLint:无法读取null的属性“范围” linting时发生
- python - 对于给定的时间戳,在数据框中查找具有最接近时间戳的行的索引
- java - 我将如何递归地重写此方法?
- docker - 如果在运行容器时没有指定镜像的版本会发生什么
- javascript - 当我单击按钮编辑我的值时,状态不会更新输入值
- r - 我怎样才能重塑这些数据看起来像这样?
- javascript - 使用 Vue 数据包含 CSS 元素
- json - 在 Json 对象 Swift 5 中解析 Json 对象
- postgresql - 使用 btree ("") (Drupal) 在零长度标识符上的 Postgres 数据库导入失败
- python - 日期发布是 Django 中的预定义函数吗?