Detect when application is launched with Push Notification

INTRODUCTION
In today’s fast moving world nobody wants to check single things by themselves now they expect things will come to them not they have to do something to get that so notification is the way which fulfils this requirement in our daily life either that is important news or messages or any alerts or any specific events or any reminder notification do this all things for us.

OVERVIEW – Detect when App launched Push Notification

Notification are of basically of two types one is local and other one is push notifications. local notification are used for scheduling any event by user itself and it will trigger at users given time and date. Whereas in push notifications backend team or any event added by app backend will fire notifications and user receive those notifications if internet is ON.

SOLUTION for App launched by Push Notification

To know whether app is launched with push notification or not we have to add a method for it which called when app is opened with clicking on push notification. Below written method is for this purpose

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
if ( application.applicationState == UIApplicationStateInactive || application.applicationState == UIApplicationStateBackground )
{
//opened app from clicking on push notification when app was in background or closed.
}
}

And same method for local notificaiton is mentioned below

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

Leave a Comment