现在的位置: 首页 > 综合 > 正文

IOS获取设备及APP相应信息

2017年02月27日 ⁄ 综合 ⁄ 共 1993字 ⁄ 字号 评论关闭

http://www.cnphp6.com/archives/61520

iOS的SDK中提供了UIDevice,NSBundle,NSLocale,UIScreen等类来获取设备、app等相应的信息。

 

UIDevice用于获取设备相应的信息,如设备名称、设备唯一标识、系统名称、系统版本号、设备模式、本地设备模式等。

 

NSBundle用于获取App相应的信息,如应用名称、应用版本、应用Build版本等。

 

NSLocale用于获取用户的本地化信息设置,例如货币类型,国家,语言,数字,日期格式的格式化,提供正确的地理位置显示等。

 

UIScreen用于获取设备的屏幕尺寸和分辨率。

 

 

相应代码如下:

 

//设备相关信息的获取

NSString *strName = [[UIDevice currentDevice] name];

NSLog(@”设备名称:%@”, strName);//e.g. “My iPhone”

NSString *strId = [[UIDevice currentDevice] uniqueIdentifier];

NSLog(@”设备唯一标识:%@”,
strId);//UUID,5.0后不可用

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

 

//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);

 

 

//Getting the User’s Language

NSArray *languageArray = [NSLocale preferredLanguages];

NSString *language = [languageArray objectAtIndex:0];

NSLog(@”语言:%@”, language);//en

NSLocale *locale = [NSLocale currentLocale];

NSString *country = [locale localeIdentifier];

NSLog(@”国家:%@”, country); //en_US

 

//屏幕尺寸

CGRect rect = [[UIScreen mainScreen] bounds];

CGSize size = rect.size;

CGFloat width = size.width;

CGFloat height = size.height;

NSLog(@”宽、高:%f,%f”,width,height);

 

//分辨率

CGFloat scale_screen = [UIScreen mainScreen].scale;

NSLog(@”screen w:%f”,width*scale_screen);

NSLog(@”screen h:%f”,height*scale_screen);

 

参考:

http://blog.csdn.net/xyz_lmn/article/details/8968196

http://blog.csdn.net/tangaowen/article/details/7597535

 

抱歉!评论已关闭.