ios - iOS 推送通知在添加 Firebase SDK 后停止工作
问题描述
我在我的项目中使用 APNS 推送通知。推送通知在添加和配置 Firebase SDK 之前运行良好。我注意到在添加 Firebase 之后,函数:didRegisterForRemoteNotificationsWithDeviceToken
没有被调用。
我不知道我是否必须在 Firebase 中禁用某些东西,如果我删除 Firebase 设置 (FirebaseApp.configure()),didRegisterForRemoteNotificationsWithDeviceToken
则会再次调用该函数。
我的代码:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// ... existing code ...
registerForPushNotifications()
return true
}
func registerForPushNotifications() {
UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound, .badge]) {
(granted, error) in
print("Permission granted: \(granted)")
guard granted else { return }
}
}
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
let tokenParts = deviceToken.map { data -> String in
return String(format: "%02.2hhx", data)
}
let token = tokenParts.joined()
print("Device Token: \(token)")
}
func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
print("Failed to register: \(error)")
}
解决方案
推荐阅读
- python - 使用 Ubuntu 20.4 和 Python Imaplib:我可以覆盖 ssl.SSLError: [SSL: DH_KEY_TOO_SMALL] 吗?
- python - 如何序列化keras模型的类对象
- .net-core - 使用 Azure DevOps 的 Delpoy NetCore 应用程序
- excel - 数字倍数的Excel条件格式
- javascript - 如何更改 Highcharts 上的 DateTime 格式?
- typescript - 页面刷新角9后保留材料徽章值
- html - 对齐两个元素的基线
- python - gzip python 2.7中现有的json文件
- python - 如何在多个文件中将某个标签中的字符串更改为小写
- cross-platform - 如何使用自动填写的凭据从电子邮件中打开应用程序