7.UIDevice

UIDevice所做的工作就是为应用程序提供用户及设备的一切信息。


一,访问设备数据.
获取系统信息
UIDevice *currentDevice = [UIDevice currentDevice]; 
//获取型号
NSString *model = [currentDevice model]; 
//获取系统版本号
NSString *systemVersion = [currentDevice systemVersion]; 
//获取系统名称
NSString *strSysName = [[UIDevice currentDevice] systemName];  
//获取设备名称
NSString *strName = [[UIDevice currentDevice] name];  
//获得设备方向
UIInterfaceOrientation orientation = [[UIApplication sharedApplication]statusBarOrientation];
//程序启动时获取当前驱动的方向的方法
[[UIDevice currentDevice]beginGeneratingDeviceOrientationNotifications];
UIDeviceOrientation currentOrientation = [ [UIDevice currentDevice]orientation];
//currentOrientation 可以获得UIDevice 正面向上 向下方向

[[UIDevice currentDevice]endGeneratingDeviceOrientationNotifications];


if(orientation == 0) //Default orientation 
 //UI is in Default (Portrait) -- this is really a just a failsafe. 
else if(orientation == UIInterfaceOrientationPortrait)
 //Do something if the orientation is in Portrait
else if(orientation == UIInterfaceOrientationLandscapeLeft)
 // Do something if Left
else if(orientation == UIInterfaceOrientationLandscapeRight)
 //Do something if right


通过NSLocale获取用户语言种类(本地化)
NSArray *languageArray = [NSLocale preferredLanguages]; 
//获取用户语言
NSString *language = [languageArray objectAtIndex:0]; 
//获取用户当前位置
NSLocale *locale = [NSLocale currentLocale]; 
//获取用户所在国家
NSString *country = [locale localeIdentifier]; 

通过NSBundle获取应用程序版本信息
NSString *appVersion = [[NSBundle mainBundle] 
objectForInfoDictionaryKey:(NSString *)kCFBundleVersionKey]; 
应用程序中的info.plist文件保存着当前应用版本信息,只要利用kCFBundleVersionKey对mainBundle进行访问,即可返回正确的应用程序版本结果

  NSDictionary *dicInfo = [[NSBundle mainBundle] infoDictionary];  
    //    CFShow(dicInfo);  
    
//获取App名称
NSString *strAppName = [dicInfo objectForKey:@"CFBundleDisplayName"];  
//获取应用版本号        
NSString *strAppVersion = [dicInfo objectForKey:@"CFBundleShortVersionString"];  
//App应用Build版本
NSString *strAppBuild = [dicInfo objectForKey:@"CFBundleVersion"];  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值