zoukankan      html  css  js  c++  java
  • 判断应用在前台还是在后台

    可以这样 判断

    #import "AppDelegate.h"

     @interface AppDelegate () {

        BOOL isActive;

    }

    @end

    @implementation AppDelegate

    //进入后台

    - (void)applicationDidEnterBackground:(UIApplication *)application {

        isActive = NO;

    }

    //进入前台 

    - (void)applicationWillEnterForeground:(UIApplication *)application {

      // Called as part of the transition from the background to the inactive state;

      // here you can undo many of the changes made on entering the background.

    }

     //处于活动状态

    - (void)applicationDidBecomeActive:(UIApplication *)application {

        isActive = YES;

    }

    @end

     

    这样就可以根据isActive来控制一些通知的显示。

     

    如:

    - (void)application:(UIApplication *)application
        didReceiveLocalNotification:(UILocalNotification *)notification {
    
      if (isActive) {
        return;
      } else {
        HDFileTableViewController *vc = [[HDFileTableViewController alloc] init];
        vc.upLoad = NO;
        vc.directoryPath = [[NSSearchPathForDirectoriesInDomains(
            NSCachesDirectory, NSUserDomainMask, YES) lastObject]
            stringByAppendingPathComponent:@"附件"];
        UINavigationController *navc =
            [[UINavigationController alloc] initWithRootViewController:vc];
    
        [self.window.rootViewController presentViewController:navc
                                                     animated:YES
                                                   completion:nil];
      }
    }
  • 相关阅读:
    开源的免费的对比工具
    win10 git bash 配置
    Java SSH 不使用终端也能调用环境变量中的指令
    MySQL WITH ROLLUP
    docker安装postgres
    开源的应用容器引擎
    清除浮动有哪几种方法
    js中的yield
    git的速学了解
    string/stringBuffer/StringBuilder的区别
  • 原文地址:https://www.cnblogs.com/hd1992/p/5130605.html
Copyright © 2011-2022 走看看