I'm using OneSignal to process notifications in my app. This is initiated in AppDelegate.swift where there is a function that handles received apps:
let notificationReceivedBlock: OSHandleNotificationReceivedBlock = { notification in
    print("Received Notification: \(notification!.payload.body)")
}
I then have a TabViewController with 5 tabs and each tab's navigationItem has a UINavigationBarButton that sends you to a messages view. I want to change the badge number in that button whenever a notification comes in to show that the user is getting new messages. I have a function inside every viewController (each of the 5 tabs) that will update this.
The problem is that the AppDelegate needs to call this function updateBadgeNumber and I don't know how to do this. Plus, some of the tabs may not even have been initialised yet. Does anyone know how to call functions in ViewControllers from the AppDelegate?
Thank you.
EDIT:
Found a solution thanks to @paulvs below. He linked me to an answer where I found this: Find Top View Controller in Swift
 
     
    