It is possible, but addressing directly members of another ViewController breaks responsibility. It is a good practice to define Interface protocols for internal interactions. In this particular case, it is a good idea to create protcol RemoteNotificationReciverInterface (or kind of RemoteNotificationReciveable according to some modern coding styles advice, although I found it difficult to find appropriate adjective in this case) :
protocol RemoteNotificationReciverInterface: class {
func didReciveNotification(info : [AnyHashable : Any])
}
Then extent your ViewController( and any view controllers that had to react on Notifications when they are topmost)
extension HomeViewController: RemoteNotificationReciverInterface {
func didReciveNotification(info : [AnyHashable : Any]) {
// Chnage you button, ignore para,eters
}
}
You can adopt UINavigationContoroller, UITabBarConroller etc. to forward notifications to their topmost controllers, like:
extension UINavigationController: RemoteNotificationReciverInterface {
func didReciveNotification(info : [AnyHashable : Any]) {
(topViewController as? RemoteNotificationReciverInterface)?.didReciveNotification(info: info)
}
}
And the easily forward it from app delegate.
func application(_ application: UIApplication,didReceiveRemoteNotification userInfo: [AnyHashable : Any],fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
if application.applicationState == .active {
(window?.rootViewController as? RemoteNotificationReciverInterface).didReciveNotification(info: userInfo)
}
}