2016-06-20 48 views
1
  1. 应用程序在iPhone上运行,用户点击主页按钮一次,应用程序将进入后台。
  2. 2或3秒后本地通知到达,用户点击本地通知。
  3. 应用程序将再次进入前景并成为活动,并且didReceiveLocalNotification将被调用。

如何通过点击本地通知而不是应用程序图标来确定应用程序变为活动状态。如何通过点击本地通知确定应用程序变为活动

+0

这看起来像http://stackoverflow.com/questions/32061897/ios-push-notification-how-to-detect-if-the-user-tapped-on-notification-when的可能欺骗-The –

回答

1

这里是检测什么是你的应用程序的状态时,发射UILocalNotification一个简单的方法,如果
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
叫,这可以确保本地通知被接收。

- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification { 
    UIApplicationState state = [application applicationState]; 
    if (state == UIApplicationStateInactive) { 
     // Application was in the background when notification was delivered. 
    } else { 

    } 
} 
相关问题