zoukankan      html  css  js  c++  java
  • iOS开发 获取手机信息(UIDevice,NSBundle,NSlocale)

    在开发中,需要获取当前设备的一些信息,可以通过UIDevice,NSbundle,NSlocale获取.

    UIDevice

    UIDevice 提供了多种属性,类函数及状态通知,可以检测手机电量,定位,感应,机型,当前系统版本等等.

    //设备相关信息的获取  
     NSString *strName = [[UIDevice currentDevice] name];  
     NSLog(@"设备名称:%@", strName);//e.g. "My iPhone"  
        
     NSString *strSysName = [[UIDevice currentDevice] systemName];  
     NSLog(@"系统名称:%@", strSysName);// e.g. @"iOS"  
       
     NSString *strSysVersion = [[UIDevice currentDevice] systemVersion];  
     NSLog(@"系统版本号:%@", strSysVersion);// e.g. @"4.0"  
       
     NSString *strModel = [[UIDevice currentDevice] model];  
     NSLog(@"设备模式:%@", strModel);// e.g. @"iPhone", @"iPod touch"  
       
     NSString *strLocModel = [[UIDevice currentDevice] localizedModel];  
     NSLog(@"本地设备模式:%@", strLocModel);// localized version of model 
    

    NSBundle  

    bundle 是一个目录,其中包含了程序会使用到的资源,这些资源包含了图像,声音,编译好的代码,通过这些亦可获取一些应用信息.

    /app应用相关信息的获取  
        NSDictionary *dicInfo = [[NSBundle mainBundle] infoDictionary];  
        //    CFShow(dicInfo);  
          
        NSString *strAppName = [dicInfo objectForKey:@"CFBundleDisplayName"];  
        NSLog(@"App应用名称:%@", strAppName);  
          
        NSString *strAppVersion = [dicInfo objectForKey:@"CFBundleShortVersionString"];  
        NSLog(@"App应用版本:%@", strAppVersion);  
          
        NSString *strAppBuild = [dicInfo objectForKey:@"CFBundleVersion"];  
        NSLog(@"App应用Build版本:%@", strAppBuild); 
    

     NSLocale 

    NsLocale可以获取用户的本地化信息,如货币,语言,国家,数字,日期格式,地理位置显示等等.

    1 //Getting the User’s Language  
    2    NSArray *languageArray = [NSLocale preferredLanguages];  
    3    NSString *language = [languageArray objectAtIndex:0];  
    4    NSLog(@"语言:%@", language);//en  
    5      
    6    NSLocale *locale = [NSLocale currentLocale];  
    7    NSString *country = [locale localeIdentifier];  
    8    NSLog(@"国家:%@", country); //en_US
  • 相关阅读:
    【HDOJ】3660 Alice and Bob's Trip
    【HDOJ】3652 B-number
    【HDOJ】4057 Rescue the Rabbit
    【HDOJ】2155 小黑的镇魂曲
    【HDOJ】2828 Lamp
    【HDOJ】3275 Light
    【HDOJ】2430 Beans
    【POJ】2823 Sliding Window
    CE下可用的3G
    RIL开发过程
  • 原文地址:https://www.cnblogs.com/shaoting/p/4949498.html
Copyright © 2011-2022 走看看