UIApplication, stand for App
- use singleton, UIApplication.shared.
Functions - operations for App level
- info number if Icon, such as badgeNumber
- Network Indicator
- statusBar (frame.size.height 20)
- statusBar notification
- open URL, Telephone Number, Message
Example
- open a url in Safari (out of current App)
- if we want to intercept a url, we can process in here ``` //打开网页 UIApplication *app = [UIApplication shareApplication]; //url: header + content
NSURL *url = [NSURL URLWithString:@"xxx"]; [app openURL:url];
//隐藏状态栏
- (BOOL) prefersStatusBarHidden {
return YES;
}
```
UIApplication Delegate
processing Application Life Cycle
press App
didFinishLaunch -> didBecomeActive (means we can begin interact)press Home
-> ResignActive(lose focus) -> didEnterBackground ( Enter into background)
For example, a incoming call interrupt current app, the current app will go into background. We may save data in herecomeBack to App
-> willEnterForegroundOther
-> applicationDIdReceiveMemoryWarning:(UIApplication*) application
memory warning, we should delete inMemory cache
-> willTerminate
app will be terminated
常见的代理方法
(void)applicationWillResignActive:(UIApplication *)application 说明:当应用程序将要入非活动状态执行,在此期间,应用程序不接收消息或事件,比如来电话了
(void)applicationDidBecomeActive:(UIApplication *)application 说明:当应用程序入活动状态执行,这个刚好跟上面那个方法相反
(void)applicationDidEnterBackground:(UIApplication *)application 说明:当程序被推送到后台的时候调用。所以要设置后台继续运行,则在这个函数里面设置即可
(void)applicationWillEnterForeground:(UIApplication *)application 说明:当程序从后台将要重新回到前台时候调用,这个刚好跟上面的那个方法相反。
(void)applicationWillTerminate:(UIApplication *)application 说明:当程序将要退出是被调用,通常是用来保存数据和一些退出前的清理工作。这个需要设置 UIApplicationExitsOnSuspend 的键值。
(void)applicationDidReceiveMemoryWarning:(UIApplication *)application 说明:iPhone 设备只有有限的内存,如果为应用程序分配了太多内存操作系统会终止应用程序的运行,在终止前会执行这个方法,通常可以在这里进行内存清理工作防止程序被终止
(void)applicationSignificantTimeChange:(UIApplication*)application 说明:当系统时间发生改变时执行
(void)applicationDidFinishLaunching:(UIApplication*)application 说明:当程序载入后执行