After the app receives a push notification, I'd like to change titles of some buttons on my main ViewController
. To achieve this behavior, I overwrote in my app delegate the method application: didReceiveRemoteNotification:
to re-instantiate the UINavigationController
with the controller I'd like to update as its root view controller, setting the buttons' titles to whatever I want:
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:self.welcomeViewController];
[self.window setRootViewController:navController];
[self.welcomeViewController.buttonToUpdate setTitle: @"Updated Text" forState: UIControlStateNormal];
}
While this may not be the best solution (maybe I could forget the UIButtons
altogether and make the view controller use a UITableView
with its rows acting as buttons?), but it works for the following scenarios:
1) The app in in the foreground. Push notification alert pops up, user touches OK, the view is updated fine.
2) The app in the background/closed. Device is in locked mode. Push notifications arrives, user unlocks the device, app is loaded, view is also updated fine.
The problem seems to arise when user is using another app for example, and push notification arrives, but the user opens the app NOT through the push notification but by tapping the app icon. In that case, application: didReceiveRemoteNotification:
seems not be called, and the view in questions never gets updated.
Hope my explanation is clear. I'm open to suggestions on different approaches, or how to handle that last scenario using my approach.
Thanks!