2

在我发送推送通知后,我希望应用程序在我的收件箱页面上打开,以便用户可以在收件箱中看到新消息。我的 AppDelegate 中有以下代码

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo{

    [self.tabController setSelectedIndex:2]; 
}

当我发送推送消息并且手机处于活动状态时,它会直接进入那里而不会发出警告。我知道这就是我的代码应该做的,但是有没有办法像这样改变它

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo{

    if(app.isActive == FALSE)
          [self.tabController setSelectedIndex:2]; 
}

对此的任何见解都会有很大帮助。谢谢!

4

3 回答 3

5

来自 Stanislav Yaglo,目标 C:如何检查应用程序当前是否处于活动状态(即用户正在使用它)?

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {

    if (application.applicationState == UIApplicationStateActive) {
        // For example, update the tab bar
    }
    else {
        self.tabController.selectedIndex = 3;
    }
}

希望能帮助到你 !

于 2012-07-10T14:05:21.320 回答
1

YES进入应用程序后,您可以设置一个布尔值,只需将布尔值设置为:

- (void)applicationWillEnterForeground:(UIApplication *)application

并将布尔值设置NO

- (void)applicationDidEnterBackground:(UIApplication *)application
于 2012-07-10T14:01:40.680 回答
1

You can tell if the application was in the foreground by checking the applicationState like so:

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
    if ( application.applicationState == UIApplicationStateActive )
        // app is in the foreground
    else
        // app was just brought from background to foreground
    ...
}
于 2012-07-10T14:05:44.497 回答