iOS项目中常见的文件
UIApplication都可以用来做什么(应用启动的第一个对象,单例)
- 1.1设置提醒消息数目
//设置提醒图标
//1.获取UIApplication对象
UIApplication *app = [UIApplication sharedApplication];
//2.注册用户通知
UIUserNotificationSettings *notice = [UIUserNotificationSettings settingsForTypes:
UIUserNotificationTypeBadge categories:nil];
[app registerUserNotificationSettings:notice];
//3.设置提醒值.
app.applicationIconBadgeNumber = 10;
- 1.2设置联网状态
UIApplication *app = [UIApplication sharedApplication];
app.networkActivityIndicatorVisible = YES;
- 1.3设置状态栏样式(改变为黑色,白色或者隐藏掉)
//1.获取UIApplication对象
UIApplication *app = [UIApplication sharedApplication];
//隐藏状态栏
//app.statusBarHidden = NO;
app.statusBarStyle = UIStatusBarStyleLightContent;
//[app setStatusBarHidden:YES animated:YES];
补充:从iOS7开始,系统提供了2种管理状态栏的方式,我自己平时也是直接在控制器里面控制状态栏样式的
通过UIViewController管理(每一个UIViewController都可以拥有自己不同的状态栏)
通过UIApplication管理(一个应用程序的状态栏都由它统一管理)
在iOS7之后,默认情况下,状态栏都是由UIViewController管理的,UIViewController实现下列方法就可以轻松管理状态栏的可见性和样式
只要实现下列方法即可
//状态栏的样式
-(UIStatusBarStyle)preferredStatusBarStyle
{
return UIStatusBarStyleLightContent;
//状态栏样式的枚举
typedef NS_ENUM(NSInteger, UIStatusBarStyle) {
UIStatusBarStyleDefault = 0, // Dark content, for use on light backgrounds
UIStatusBarStyleLightContent NS_ENUM_AVAILABLE_IOS(7_0) = 1, // Light content, for use on dark backgrounds
UIStatusBarStyleBlackTranslucent NS_ENUM_DEPRECATED_IOS(2_0, 7_0, "Use UIStatusBarStyleLightContent") = 1,
UIStatusBarStyleBlackOpaque NS_ENUM_DEPRECATED_IOS(2_0, 7_0, "Use UIStatusBarStyleLightContent") = 2,
} __TVOS_PROHIBITED;
}
//状态栏的可见性
-(BOOL)prefersStatusBarHidden;
- 1.4应用级别的操作(打电话,发短信,发邮件,打开一个url,跳转到别的应用)
//打开url
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"https://www.google.com"]];
//跳转到微信
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"weixin://"]];
//打电话
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel://4008213311"]];
Appdelegate
- 2.1Appdelegate的头文件(是UIApplication的代理)
#import
@interface AppDelegate : UIResponder
@property (strong, nonatomic) UIWindow *window;
@end
- 2.2Appdelegate的代理方法(每个方法里面都有说明)
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
//应用程序启动完毕就会调用这个方法
//记得前一段,老板提了个需求:在程序启动时候让启动图片显示3s以上,需求合理不合理我们不讨论,如果真的要这样做,就可以在这个方法里实现,
比如直接 sleep掉3s时间,启动图片就会一直显示;
return YES;
}
- (void)applicationWillResignActive:(UIApplication *)application {
//应用程序失去焦点
//比如你点击了home键盘,返回到主页面,应用程序就会调这个方法
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}
- (void)applicationDidEnterBackground:(UIApplication *)application {
//比如你点击了home键盘,返回到主页面,应用程序就会调这个方法,应用程序进入后台
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}
- (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 {
//应用程序获取焦点,程序启动时候,或者挂起后重新进入就会调用这个
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}
- (void)applicationWillTerminate:(UIApplication *)application {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}
Pch文件
pch文件有什么作用?
存放一些全局的宏(整个项目中都用得上的宏)
用来包含一些全部的头文件(用起来频率很高的类,比如自己写的一些工具类,或者屏幕适配类)
能自动打开或者关闭日志输出功能
提示:在项目中创建pch文件之后,记得在Build Setting添加pch头文件的路径.
info.plist文件
项目中重要的配置信息文件(比如Boundle id)
plist也属于文本文件,并以XML格式进行内容的组织,我们可以用任何支持UTF-8的文本编辑器打开并对其进行各种编辑操作。但因为Xcode本身提供的对于plist文件内容的操作已经非常方便,基本上利用Xode编辑就已经很方便了.
比如我自己项目中的pch文件:
苹果官网关于info.plist文件的描述