今天在看 SDImageCache 的时候注意到初始化的时候注册了两个通知 UIApplicationWillTerminateNotification 通知 和 UIApplicationDidEnterBackgroundNotification 通知
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(deleteOldFiles)
name:UIApplicationWillTerminateNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(backgroundDeleteOldFiles)
name:UIApplicationDidEnterBackgroundNotification
object:nil];
通过名称可以看出 UIApplicationDidEnterBackgroundNotification 是应用进入后台的时候调用 , 经过测试 ,没有问题 !
UIApplicationWillTerminateNotification 是应用即将终止的时候调用,但是我发现并没有调用 , Google 了一下
得出最终结论 :
1.应用在前台,双击 Home 键 ,终止应用 , UIApplicationWillTerminateNotification 调用
2.应用在前台,单击 Home 键,进入桌面 , 再终止应用 UIApplicationWillTerminateNotification 不会被调用.