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 正面向上 向下方向
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"];
一,访问设备数据.
获取系统信息
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
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"];