---
title: "IOS开发 - AppDelegate的代理方法"
author: "cwlong"
date: "2015-08-20T11:56:34Z"
tags: []
categories: ["移动开发"]
slug: "ios-appdelegate"
draft: false
lastmod: "2015-08-20T17:42:03Z"
id: 2236811
url: "https://cwlong.iteye.com/blog/2236811"
---

<span style="color:red"> 
1. [Info.plist和pch文件的作用](http://cwlong.iteye.com/admin/blogs/2236795)

 2. [UIApplication的常见使用](http://cwlong.iteye.com/blog/2236809)

 3. [AppDelegate的代理方法](http://cwlong.iteye.com/blog/2236811)

 4. [UIApplication , AppDelegate , UIWindow , UIViewController 的关系](http://cwlong.iteye.com/blog/2236810)

 5. [IOS程序的完整启动过程](http://cwlong.iteye.com/blog/2236812)
</span>


﹣AppDelegate的代理方法﹣﹣﹣﹣﹣﹣﹣﹣﹣﹣﹣﹣﹣﹣﹣我是分割线﹣﹣﹣﹣﹣﹣﹣﹣﹣﹣﹣﹣﹣﹣﹣﹣﹣﹣﹣﹣﹣﹣

现阶段的移动操作设备都有个特点 , 一个应用程序运行的过程中, 很容易受到打扰, 比如一个来电或者锁屏等操作,会导致应用程序进入后台或者终止

当发生这种情况的时候 , 应用程序受到干扰时, 会产生一些系统事件, 这时UIApplication会通知它的delegate对象 , 让delegate代理这些系统事件


```c

/**
 *  一般在这里保存应用的数据
 */
- (void)applicationDidEnterBackground:(UIApplication *)application {   
    NSLog(@"进入后台的时候会调用 -- applicationDidEnterBackground");
}


- (void)applicationWillEnterForeground:(UIApplication *)application {
    NSLog(@"从后台进入时调用该方法 -- applicationWillEnterForeground");
}

/**
 *  一般在这里清除不需要的内存
 */
- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application
{
    NSLog(@"内存警告的时候会调用 -- applicationDidReceiveMemoryWarning");
}

/**
 *  在App启动完毕后,就会调用该方法
 */
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    return YES;
}


```




![](http://dl2.iteye.com/upload/attachment/0111/1057/cf58f6c7-d3e2-32e5-bb5b-0b6f4bb506b3.png)

模拟内存方法 : Hardware -> Simulate Memory Warning