检测应用程序是否从推送通知启动/打开 [英] Detect if the app was launched/opened from a push notification
本文介绍了检测应用程序是否从推送通知启动/打开的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以通过推送通知知道应用是否已启动/打开?
Is it possible to know if the app was launched/opened from a push notification?
我想可以在此处捕获启动事件:
I guess the launching event can be caught here:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
if (launchOptions != nil) {
// Launched from push notification
NSDictionary *notification = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
}
}
但是,当应用程序在后台时,我如何检测它是从推送通知中打开的?
However, how can I detect it was opened from a push notification when the app was in background?
推荐答案
查看此代码:
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
if ( application.applicationState == UIApplicationStateInactive || application.applicationState == UIApplicationStateBackground )
{
//opened from a push notification when the app was on background
}
}
与
-(void)application:(UIApplication *)application didReceiveLocalNotification (UILocalNotification *)notification
这篇关于检测应用程序是否从推送通知启动/打开的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文