Sunday, December 4, 2022
HomeiOS Developmentios - How can I observe an APNs from Firebase if app...

ios – How can I observe an APNs from Firebase if app is in foreground?


I get APNs from cloud features / FCM, and I wish to make a name to my backend (Firestore) when the notification is noticed by the shopper when the app is open.

This needs to be accomplished on the shopper facet because the app is open, I can already observe when a notification occurs with this:

func userNotificationCenter(_ heart: UNUserNotificationCenter,
                              willPresent notification: UNNotification) async -> UNNotificationPresentationOptions {
    let userInfo = notification.request.content material.userInfo
    print("userInfo: (userInfo)")
        
    return [[.banner, .list, .sound]]
}

Nevertheless, I’ve this saved in my AppDelegate utilizing a UIApplicationDelegateAdaptor for the reason that app is utilizing SwiftUI.

This implies I can’t entry any of my view fashions or firebase frameworks from this perform. So, I’m pressured to determine the way to observe notifications from inside SwiftUI views, fairly than the AppDelegate.

In SwiftUI, how can I observe my app is displaying a notification, whereas the app is open?

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments