iOS项目开发常用代码1
<1>获取全局AppDelegate实例对象,该类是单例(Singleton)
AppDelegate *app = (AppDelegate *)[[UIApplication sharedApplication] delegate];
<2> 获取屏幕的大小
CGRect frame = [[UIScreen mainScreen] bounds];
<3> 获取当前系统的版本号
NSLog([[UIDevice currentDevice] name]);//iPhone Simulator
NSLog([[UIDevice currentDevice] uniqueIdentifier]);//2FD4D2CE-5FF2-587C-89E9-1BD449D22E66
NSLog([[UIDevice currentDevice] systemName]); ///iPhone OS
NSLog([[UIDevice currentDevice] systemVersion]);//5.1
NSLog([[UIDevice currentDevice] model]); /// iPhone Simulator
NSLog([[UIDevice currentDevice] localizedModel]);///iPhone Simulator
float systemVersion = [[[UIDevice currentDevice] systemVersion] floatValue];
<4> 获取App的版本号和Build号
NSString* appVersion = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"];
NSString* appBuild = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"];
<5> 添加震动
AudioServicesPlaySystemSound (kSystemSoundID_Vibrate);
<6>获取系统所支持的国际化信息
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSArray *arrayLanguage = [defaults objectForKey:@"AppleLanguages"];
NSLog(@"%@", arrayLanguage);
<7> 字符串格式化符号
%@ 对象
%d, %i 整数
%u 无符整形
%f 浮点/双字
%x, %X 二进制整数
%o 八进制整数
%p 指针
%e 浮点/双字 (科学计算)
%g 浮点/双字
%s C 字符串
%.*s Pascal字符串
%c 字符
%C unichar
%lld 64位长整数(long long)
%llu 无符64位长整数
%Lf 64位双字