My app receiving push notification, and showing appropriate info message for that. However when I'm clicking to the message, application becomes active but application didFinishLaunchingWithOptions is not getting called which is right i think, since the application is not suspended and it just resigns active. The question is how i can make sure that user clicked to message when application becomes to foreground ?
Notifications could be created at any moment (on Foreground, Background or even when the application is terminated/killed).
When your app is in the background, Android directs notification messages to the system tray. A user tap on the notification opens the app launcher by default. This includes messages that contain both notification and data payload (and all messages sent from the Notifications console).
Apple does not offer a way to handle a notification that arrives when your app is closed (i.e. when the user has fully quit the application or the OS had decided to kill it while it is in the background). If this happens, the only way to handle the notification is to wait until it is opened by the user.
I think what you are looking for is this app delegate method:
- (void)application:(UIApplication *)application
didReceiveRemoteNotification:(NSDictionary *)userInfo
It will be called if your app is backgrounded, and the notification payload will be delivered in the userInfo dictionary. This contrasts with the situation when the app is launched from cold start, when this method does not get called, and instead you check in the launchOptions dictionary for the payload.
However the preferred way to do this since iOS7 is to use this:
- (void)application:(UIApplication *)application
didReceiveRemoteNotification:(NSDictionary *)userInfo
fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler;
This method is called when a user taps on a notification, regardless of whether the app is launched from cold start or foregrounded from background. So even if you are not using the completionHandler, it provides a more consistent way of accessing the notification payload. If this method is present, the older one does not get called.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With