IOS 6: updated view after push notification, but the application was closed

After the application receives a push notification, I would like to change the names of some buttons on my main ViewController . To achieve this behavior, I rewrote the application: didReceiveRemoteNotification: method in my case to re-create the UINavigationController instance with the controller that I would like to update as its root view controller, setting the button names 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]; } 

Although this may not be the best solution (maybe I could completely forget the UIButtons and force the view controller to use the UITableView with its rows acting like buttons?), But it works for the following scenarios:

1) The application is in the foreground. The message "Push alert alert" appears, the user touches "OK", the view is updated perfectly.

2) The application is in the background / closed. The device is in lock mode. Push notifications are received, the user unlocks the device, the application loads, the viewing is also perfectly updated.

The problem occurs when the user uses another application, for example, and sends a notification, but the user opens the NOT application through a push notification, but by clicking the application icon. In this case, application: didReceiveRemoteNotification: does not seem to be called, and the representation in questions is never updated.

Hope my explanation is clear. I am open to suggestions on various approaches or how to handle this last scenario using my approach.

Thanks!

+4
source share
1 answer

In the APNS development guide:

Let's look at possible scenarios when a local notification or remote notification for an application.

A notification is delivered when the application is not running in the foreground. In this case, the system presents a notification, a warning display, an icon icon, possibly a sound.

As a result of the notification, the user deletes the action of the warning button or short-term pressing (or pressing) the application icon. If the action button is pressed (on a device running iOS), the system launches the application and the application calls its delegates application: didFinishLaunchingWithOptions: method (if implemented); This passes in the notification payload (for remote notifications) or the local notification object (for local notifications).

If the application icon is displayed on an iOS device, the application calls the same method , but does not provide any notification information .

The behavior you are experiencing is the expected behavior when you click the application icon. In this case, as if the user started the application normally, and a push notification was not received. The only way (I can think of it) to show you something else in this case is to contact your server when the application starts and get some information that indicates that a push notification has recently been sent to this device.

+8
source

All Articles