目标C:如何检查应用程序当前是活动(即用户在使用它)? [英] Objective C: How to check if application is currently active (i.e. user is using it)?

查看:220
本文介绍了目标C:如何检查应用程序当前是活动(即用户在使用它)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我实现了APNS推动我的应用程序有以下行为

1)如果应用程序是不是在后台继续运行,即或没有推出尚未

用户将收到一个弹出消息,在点击将带来他/她的第三个标签中的应用程序(见code以下)

   - (无效)应用:(*的UIApplication)的应用didReceiveRemoteNotification:(NSDictionary的*)USERINFO
{    self.tabController.selectedIndex = 3;}

2)如果您的应用启动和当前活动

没有弹出警告将显示与新通知的数量将显示在第3个选项卡上号

我的问题是我怎么能确定用户的应用程序被激活?
如何和我在哪里可以实现检查,这样我可以设置2个不同的行为?


解决方案

   - (无效)应用:(*的UIApplication)的应用didReceiveRemoteNotification:(NSDictionary的*)USERINFO
{
    如果(application.applicationState == UIApplicationStateActive){
        //更新标签栏项目
    }
    其他{
        self.tabController.selectedIndex = 3;
    }
}

I am implementing an APNS push for my app with the following behaviours

1) If app is not active i.e. in background or not launched yet:

User will receive a pop up message and on click will bring him/her to the 3rd tab in the app (see code below)

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

    self.tabController.selectedIndex = 3;

}

2) If app is launch and currently active

No popup alert will be shown and the number of new notifications will show as a number on the 3rd tab

My question is how can I determine if the user's app is active? How and where can I implement the check so that I can set the 2 different behaviours?

解决方案

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
    if (application.applicationState == UIApplicationStateActive) {
        // update the tab bar item
    }
    else {
        self.tabController.selectedIndex = 3;
    }
}

这篇关于目标C:如何检查应用程序当前是活动(即用户在使用它)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆