[英]How to know if app user click on push notification ios?
我想检测用户是否单击推送通知以启动应用程序。
只需在您的AppDelegate中实现方法
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo;
If the application was not running the didFinishLaunchingWithOptions method gets called when the application starts and you can check the launchOptions parameters like this: 如果应用程序未运行,则在应用程序启动时会调用didFinishLaunchingWithOptions方法,您可以像下面这样检查launchOptions参数:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
if (launchOptions != nil) {
NSDictionary *notification = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
if (notification) {
// Launched from push notification
}
}
}
If the application is already launched you can use this method: 如果应用程序已经启动,则可以使用以下方法:
- (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
}
}
You can also check: Detect if the app was launched/opened from a push notification 您还可以检查: 通过推送通知检测应用程序是否已启动/打开
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.