我想检测用户是否点击推送通知以启动app.or以将其置于前台。
答案 0 :(得分:0)
在AppDelegate中实现方法
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo;
答案 1 :(得分:0)
如果应用程序未运行,则在应用程序启动时调用didFinishLaunchingWithOptions方法,您可以检查launchOptions参数,如下所示:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
if (launchOptions != nil) {
NSDictionary *notification = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
if (notification) {
// Launched from push notification
}
}
}
如果应用程序已经启动,您可以使用此方法:
- (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
}
}
您还可以查看: Detect if the app was launched/opened from a push notification