If you ever download Telegram App or other messaging application, you will see that when you are inside the app (the app status is active), when someone message you, it will show you custom notification inside the app on the top of the screen. When you touch that custom notification, it will redirect you to the chat screen.
But when the app is inactive (the app is in background), and you get the chat notification outside the app, probably on the lock screen or another app. If you touch it, it will open the app and redirect you to the chat screen without in-app custom notification.
To do this I think I should know how to determine is the app opened from the notification or not. Question, how to determine if the app opened from notification or currently active?
Objective-C:
-(void) application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
if ([UIApplication sharedApplication].applicationState==UIApplicationStateActive) {
NSLog(@"App already open");
} else {
NSLog(@"App opened from Notification");
}
}
Swift:
func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) {
if application.applicationState == UIApplicationState.active {
print("App already open")
} else {
print("App opened from Notification")
}
}
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