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

只需关闭 FCM 中的方法重排:https://firebase.google.com/docs/cloud-messaging/ios/client#method_swizzling_in

相关内容

  • 没有找到相关文章

最新更新