Is it any way to known when an iOS app is launched, if Push notifications were sent to the device ? ( I want to access to the payload to retrieve information from the notification )
Thanks,
Is it any way to known when an iOS app is launched, if Push notifications were sent to the device ? ( I want to access to the payload to retrieve information from the notification )
Thanks,
There are methods from UIApplicationDelegate from where you see if there is notification received
You could see in your AppDelegate didFinishLaunchingWithOptions
method if user has launced the app with the notifications e.g
UILocalNotification *notif =
[launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey];
if (localNotif) {
irLog(@"Recieved Notification");
}
for local notification you have posted you can have a look at this method
- (void)application:(UIApplication *)app didReceiveLocalNotification:(UILocalNotification *)notif
for remote notifications you can have a look at this method
-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
You should add something like this to your code :
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary
*)launchOptions {
NSDictionary *remoteNotif = [launchOptions objectForKey: UIApplicationLaunchOptionsRemoteNotificationKey];
//Accept push notification when app is not open
if (remoteNotif) {
[self handleRemoteNotification:application userInfo:remoteNotif];
return YES;
}
return YES;
}
Note that you will only get the push notification payload if the app was launched by tapping the notification. If it was launched by tapping the app icon, you won't get the payload.