iOS項(xiàng)目中常見(jiàn)的文件
UIApplication都可以用來(lái)做什么(應(yīng)用啟動(dòng)的第一個(gè)對(duì)象,單例)
- 1.1設(shè)置提醒消息數(shù)目
//設(shè)置提醒圖標(biāo)
//1.獲取UIApplication對(duì)象
UIApplication *app = [UIApplication sharedApplication];
//2.注冊(cè)用戶(hù)通知
UIUserNotificationSettings *notice = [UIUserNotificationSettings settingsForTypes:
UIUserNotificationTypeBadge categories:nil];
[app registerUserNotificationSettings:notice];
//3.設(shè)置提醒值.
app.applicationIconBadgeNumber = 10;
- 1.2設(shè)置聯(lián)網(wǎng)狀態(tài)
UIApplication *app = [UIApplication sharedApplication];
app.networkActivityIndicatorVisible = YES;
- 1.3設(shè)置狀態(tài)欄樣式(改變?yōu)楹谏?白色或者隱藏掉)
//1.獲取UIApplication對(duì)象
UIApplication *app = [UIApplication sharedApplication];
//隱藏狀態(tài)欄
//app.statusBarHidden = NO;
app.statusBarStyle = UIStatusBarStyleLightContent;
//[app setStatusBarHidden:YES animated:YES];
補(bǔ)充:從iOS7開(kāi)始,系統(tǒng)提供了2種管理狀態(tài)欄的方式,我自己平時(shí)也是直接在控制器里面控制狀態(tài)欄樣式的
通過(guò)UIViewController管理(每一個(gè)UIViewController都可以擁有自己不同的狀態(tài)欄)
通過(guò)UIApplication管理(一個(gè)應(yīng)用程序的狀態(tài)欄都由它統(tǒng)一管理)
在iOS7之后,默認(rèn)情況下,狀態(tài)欄都是由UIViewController管理的,UIViewController實(shí)現(xiàn)下列方法就可以輕松管理狀態(tài)欄的可見(jiàn)性和樣式
只要實(shí)現(xiàn)下列方法即可
//狀態(tài)欄的樣式
-(UIStatusBarStyle)preferredStatusBarStyle
{
return UIStatusBarStyleLightContent;
//狀態(tài)欄樣式的枚舉
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;
}
//狀態(tài)欄的可見(jiàn)性
-(BOOL)prefersStatusBarHidden;
- 1.4應(yīng)用級(jí)別的操作(打電話,發(fā)短信,發(fā)郵件,打開(kāi)一個(gè)url,跳轉(zhuǎn)到別的應(yīng)用)
//打開(kāi)url
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"https://www.google.com"]];
//跳轉(zhuǎn)到微信
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"weixin://"]];
//打電話
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel://4008213311"]];
Appdelegate
- 2.1Appdelegate的頭文件(是UIApplication的代理)
#import <UIKit/UIKit.h>
@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@end
- 2.2Appdelegate的代理方法(每個(gè)方法里面都有說(shuō)明)
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
//應(yīng)用程序啟動(dòng)完畢就會(huì)調(diào)用這個(gè)方法
//記得前一段,老板提了個(gè)需求:在程序啟動(dòng)時(shí)候讓啟動(dòng)圖片顯示3s以上,需求合理不合理我們不討論,如果真的要這樣做,就可以在這個(gè)方法里實(shí)現(xiàn),
比如直接 sleep掉3s時(shí)間,啟動(dòng)圖片就會(huì)一直顯示;
return YES;
}
- (void)applicationWillResignActive:(UIApplication *)application {
//應(yīng)用程序失去焦點(diǎn)
//比如你點(diǎn)擊了home鍵盤(pán),返回到主頁(yè)面,應(yīng)用程序就會(huì)調(diào)這個(gè)方法
// 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 {
//比如你點(diǎn)擊了home鍵盤(pán),返回到主頁(yè)面,應(yīng)用程序就會(huì)調(diào)這個(gè)方法,應(yīng)用程序進(jìn)入后臺(tái)
// 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 {
//應(yīng)用程序獲取焦點(diǎn),程序啟動(dòng)時(shí)候,或者掛起后重新進(jìn)入就會(huì)調(diào)用這個(gè)
// 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文件有什么作用?
存放一些全局的宏(整個(gè)項(xiàng)目中都用得上的宏)
用來(lái)包含一些全部的頭文件(用起來(lái)頻率很高的類(lèi),比如自己寫(xiě)的一些工具類(lèi),或者屏幕適配類(lèi))
能自動(dòng)打開(kāi)或者關(guān)閉日志輸出功能
提示:在項(xiàng)目中創(chuàng)建pch文件之后,記得在Build Setting添加pch頭文件的路徑.
info.plist文件
項(xiàng)目中重要的配置信息文件(比如Boundle id)
plist也屬于文本文件,并以XML格式進(jìn)行內(nèi)容的組織,我們可以用任何支持UTF-8的文本編輯器打開(kāi)并對(duì)其進(jìn)行各種編輯操作。但因?yàn)閄code本身提供的對(duì)于plist文件內(nèi)容的操作已經(jīng)非常方便,基本上利用Xode編輯就已經(jīng)很方便了.
比如我自己項(xiàng)目中的pch文件:
