I'm not sure if anyone have experienced this case, but it's like this:
I've finished the APNS, the app did receive the notification. It worked fine when I open the app from the notification (which call appDidReceiveRemoteNotification:
).
Strange thing is, when app is on background, it receive a notification (show up in the notification box). When I open the app by tap on the icon (not the notification), the debugger didn't stop at either appDidReceiveRemoteNotification:
or appDidFinishLaunchWithOption:
, so my notification did not saved. When I pull the notification box down again and tap on the notification, the debugger stop at appDidReceiveRemoteNotification:
as expected. How do I update the notification by open app on the app icon?
** EDIT **
Thanks to abhinav, I realized that I miss-use the method. I should use either
- (void)applicationWillEnterForeground:(UIApplication *)iApplication // Or
- (void)applicationDidBecomeActive:(UIApplication *)iApplication.
But, my app is design show a server can send message (about update, news...) to the user. The code like this:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
//....
if (launchOptions) {
NSDictionary *dictionary = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
if (dictionary) {
[Message saveMessage:dictionary];
NSLog(@"Launched from push notification: %@", dictionary);
}
}
//....
}
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
// Save message to coredata.
[Message saveMessage:userInfo];
// Perform seggue, showing inbox viewcontrollers here.
}
But both the method use when open app from background doesn't provide notification dictionary, and my boss required me to update the coredata when open app from background like that, how could I do that? Or should I tell my boss that can't be acquired? We don't want user to miss a notification about updates.
You are doing nothing different for notification case here. When application is in background and user tap on application icon, irrespective of whether or not a push notification was received, you get call back on below methods.
- (void)applicationWillEnterForeground:(UIApplication *)iApplication
- (void)applicationDidBecomeActive:(UIApplication *)iApplication
application:didFinishLaunchingWithOptions:
is a method that gets called at application launch time - triggered either first time or a notification. And appDidReceiveRemoteNotification:
gets called when application is awakened with a notification tap.
So, to answer your question - you are experiencing natural iOS behaviour!!!
EDIT:
If I were you, I would have gone to my boss and explain the way iOS work. And politely tell him that its not possible. When in background, unless user intended to see the delivered notification, iOS does not allow you to get the details.