【发布时间】:2016-07-24 10:09:11
【问题描述】:
我想检测用户是否点击推送通知来启动应用程序。或者将其置于前台。
【问题讨论】:
标签: ios push-notification apple-push-notifications push
我想检测用户是否点击推送通知来启动应用程序。或者将其置于前台。
【问题讨论】:
标签: ios push-notification apple-push-notifications push
只需在你的 AppDelegate 中实现方法
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo;
【讨论】:
如果应用程序未运行,则在应用程序启动时调用 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
【讨论】: