Hi We have a project with target for QA and target for production wrote in swift, and target for watch wrote in swiftui. in the both first targets, the push notification worked well, but in the watch target, push notification did received function called but get empty user info. I can not understand what the problem could be. Maybe a certain definition is missing, or the problem was created due to the incorrect management of the targets. Because currently most of the code related to Push is in App Delegate Please help me. Thank you
This is the class with the push notification delegate functions:
import UserNotifications
import SwiftUI
class NotificationCenter: NSObject, ObservableObject {
@Published var request: UNNotificationRequest?
override init() {
super.init()
setUpNotificationPreferences()
}
func setUpNotificationPreferences() {
let center = UNUserNotificationCenter.current()
center.delegate = self
center.requestAuthorization(options: [.alert, .sound]) { (granted, error) in
if granted {
let category = UNNotificationCategory(identifier: "SAVE_CATEGORY", actions: [], intentIdentifiers: [], options: [])
center.setNotificationCategories(Set([category]))
} else {
print("No permission" + error.debugDescription)
}
}
}
}
extension NotificationCenter: UNUserNotificationCenterDelegate {
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
self.request = notification.request
completionHandler([.alert, .sound, .badge])
}
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
self.request = response.notification.request
completionHandler()
}
}