iOS项目开发经验:【常用代码1】

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位双字






  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值