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
  • 相关阅读:
    【内存泄漏】方法三:利用linux的valgrind命令定位内存泄露(Memory Leak)
    【内存泄漏】方法二:利用linux的mtrace命令定位内存泄露(Memory Leak)
    Windows下sqlmap的使用_01
    关于安装和使用BurpSuite及Java环境的配置问题
    Windows下修改环境变量的几种方法
    OPPO VOOC快充原理
    在线代码运行
    Linux在线学习模拟器
    socket设置为非阻塞模式
    pthread_mutexattr_t设置的相关函数及其说明
  • 原文地址:https://www.cnblogs.com/shaoting/p/4949498.html
Copyright © 2011-2022 走看看