S.J S.J - 5 months ago 26
Objective-C Question

How to determine background app come to foreground in action of tapping local notification

Apple doc Getting the User’s Attention While in the Background says


Notifications are a way for an app that is suspended, is in the
background, or is not running to get the user’s attention.


My app is waked by iOS because of region monitoring and
is in the background
and post a local notification. User tap the notification and app will be in foreground.

How to determine app comes in foreground because of notification tapped by user?

Which delegate method will contains the notification information.

didFinishLaunchingWithOption or didReceiveLocalNotification

Answer

If you your app running in background and you are tapped on LocalNotification Banner then you will get called following method:

-(void) application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification

after iOS 8:

- (void)application:(UIApplication *)application handleActionWithIdentifier:(NSString *)identifier forLocalNotification:(UILocalNotification *)notification completionHandler:(void(^)())completionHandler

if app is not running in background you will get notification at:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
if ([launchOptions valueForKey:@"UIApplicationLaunchOptionsLocalNotificationKey"]) {
 // here you will get
}