• ios 获取手机信息(UIDevice、NSBundle、NSLocale)


    iOS的SDK中提供了UIDevice。NSBundle,NSLocale。


    UIDevice

           UIDevice提供了多种属性、类函数及状态通知,帮助我们全方位了解设备状况。

    从检測电池电量到定位设备与临近感应。UIDevice所做的工作就是为应用程序提供用户及设备的一些信息。UIDevice类还能够收集关于设备的各种详细细节。比如机型及iOS版本号等。

    当中大部分属性都对开发工作具有积极的辅助作用。

    以下的代码简单的使用UIDevice获取手机属性。


    1. //设备相关信息的获取  
    2.  NSString *strName = [[UIDevice currentDevice] name];  
    3.  NSLog(@"设备名称:%@", strName);//e.g. "My iPhone"  
    4.    
    5.  NSString *strId = [[UIDevice currentDevice] uniqueIdentifier];  
    6.  NSLog(@"设备唯一标识:%@", strId);//UUID,5.0后不可用  
    7.    
    8.  NSString *strSysName = [[UIDevice currentDevice] systemName];  
    9.  NSLog(@"系统名称:%@", strSysName);// e.g. @"iOS"  
    10.    
    11.  NSString *strSysVersion = [[UIDevice currentDevice] systemVersion];  
    12.  NSLog(@"系统版本号号:%@", strSysVersion);// e.g. @"4.0"  
    13.    
    14.  NSString *strModel = [[UIDevice currentDevice] model];  
    15.  NSLog(@"设备模式:%@", strModel);// e.g. @"iPhone", @"iPod touch"  
    16.    
    17.  NSString *strLocModel = [[UIDevice currentDevice] localizedModel];  
    18.  NSLog(@"本地设备模式:%@", strLocModel);// localized version of model  


    NSBundle

        bundle是一个文件夹,当中包括了程序会使用到的资源. 这些资源包括了如图像,声音,编译好的代码,nib文件(用户也会把bundle称为plug-in). 相应bundle,cocoa提供了类NSBundle.一个应用程序看上去和其它文件没有什么差别. 可是实际上它是一个包括了nib文件,编译代码,以及其它资源的文件夹. 我们把这个文件夹叫做程序的main bundle。通过这个路径能够获取到应用的信息,比如应用名、版本号号等。



    1. //app应用相关信息的获取  
    2.     NSDictionary *dicInfo = [[NSBundle mainBundle] infoDictionary];  
    3.     //    CFShow(dicInfo);  
    4.       
    5.     NSString *strAppName = [dicInfo objectForKey:@"CFBundleDisplayName"];  
    6.     NSLog(@"App应用名称:%@", strAppName);  
    7.       
    8.     NSString *strAppVersion = [dicInfo objectForKey:@"CFBundleShortVersionString"];  
    9.     NSLog(@"App应用版本号:%@", strAppVersion);  
    10.       
    11.     NSString *strAppBuild = [dicInfo objectForKey:@"CFBundleVersion"];  
    12.     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  
    9.     

  • 相关阅读:
    docker笔记(1)
    解决MySQL8 #1227 – Access denied; you need (at least one of) the SYSTEM_USER privilege(s) for this ...
    nginx if判断&&和||写法
    泡泡后台Couchbase缓存使用经验分享
    ARTS-WEEK-007
    ARTS-WEEK-006
    ARTS-WEEK-005
    ARTS-WEEK-004
    ARTS-WEEK-003
    总结httpclient资源释放和连接复用
  • 原文地址:https://www.cnblogs.com/zhchoutai/p/8391637.html
Copyright © 2020-2023  润新知