如何在当前显示的控制器里判断程序是否被杀死?

通过添加通知:

//1、添加进入后台的判断
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(comeHome:) name:@"UIApplicationDidEnterBackgroundNotification" object:nil];

  • (void)comeHome:(UIApplication *)application {
    NSLog(@"进入后台");
    }

//2、添加程序被杀死的判断
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationWillTerminate:) name:@"UIApplicationWillTerminateNotification" object:nil];

  • (void)applicationWillTerminate:(UIApplication *)application {
    NSLog(@"程序被杀死");
    }

你可能感兴趣的:(如何在当前显示的控制器里判断程序是否被杀死?)