首页 > 代码库 > IOS获取设备信息
IOS获取设备信息
概要
IOS获取设备信息一般是通过UIDevice,UIScreen,NSBundle,NSLocal等方式,如果说要获取设备的内存、处理器信息,似乎可以依照Unix获取类似信息方式。
UIDevice提供了多种属性、类函数及状态通知,包括检测电池电量和定位设备与临近感应,UIDevice所做的工作就是为应用程序提供用户及设备的一些信息。UIDevice类还能够收集关于设备的各种具体细节,例如机型及iOS版本等。其中大部分属性都对开发工作具有积极的辅助作用
代码示例
- (void) getDeviceInfo { UIDevice* curDev = [UIDevice currentDevice]; /** 设备系统信息*/ // 设备名称 NSLog(@"\tname : %@", curDev.name); // 设备模式 NSLog(@"\tmodel : %@", curDev.model); // 设备本地模式 NSLog(@"\tlocalize : %@", curDev.localizedModel); // 系统名称 NSLog(@"\tos name : %@", curDev.systemName); // 系统版本号 NSLog(@"\tos version : %@", curDev.systemVersion); // 设备类别:手机,平板电脑 switch (curDev.userInterfaceIdiom) { case UIUserInterfaceIdiomPhone: NSLog(@"\tIdiom : iPhone"); break; case UIUserInterfaceIdiomPad: NSLog(@"\tIdiom : iPad"); break; default: NSLog(@"\tIdiom : Unknow"); break; } // 设备唯一标识 NSLog(@"\tUUID : %@", curDev.identifierForVendor.UUIDString); /** 设备方向 */ // 设备朝向 switch (curDev.orientation) { case UIDeviceOrientationPortrait: NSLog(@"\torientation : Portrait"); break; case UIDeviceOrientationPortraitUpsideDown: NSLog(@"\torientation : upside down"); break; case UIDeviceOrientationLandscapeLeft: NSLog(@"\torientation : left"); break; case UIDeviceOrientationLandscapeRight: NSLog(@"\torientation : right"); break; case UIDeviceOrientationFaceUp: NSLog(@"\torientation : face up"); break; case UIDeviceOrientationFaceDown: NSLog(@"\torientation : face down"); break; default: NSLog(@"\torientation : Unknow"); break; } UIScreen* mainScreen = [UIScreen mainScreen]; // 屏幕尺寸 NSLog(@"screen size : %.0fx%.0f", mainScreen.bounds.size.width, mainScreen.bounds.size.height); /** 设备电池 */ NSLog(@"Battery infomation"); // 电量 NSLog(@"\tlevel : %.2f%%", curDev.batteryLevel*100); switch (curDev.batteryState) { case UIDeviceBatteryStateUnplugged: NSLog(@"\tstate : Unplugged"); break; case UIDeviceBatteryStateCharging: NSLog(@"\tstate : Charging"); break; case UIDeviceBatteryStateFull: NSLog(@"\tstate : Full"); break; default: NSLog(@"\tstate : Unknow"); break; } // 电池监视器是否开启 if( curDev.isBatteryMonitoringEnabled ) { NSLog(@"\tmonitor on : YES"); } else { NSLog(@"\tmonitor on : NO"); } /** 体感器 */ NSLog(@"Proximity Sensor infomation"); if( curDev.proximityState ) { NSLog(@"\tsensor on : YES"); } else { NSLog(@"\tsensor on : NO"); } if(curDev.proximityMonitoringEnabled) { NSLog(@"\tmonitor on : YES"); } else { NSLog(@"\tmonitor on : NO"); } } - (void) getBundleInfo { NSBundle* bundle = [NSBundle mainBundle]; NSDictionary* bundleInfo = [bundle infoDictionary]; // 应用信息 NSLog(@"%@", bundleInfo); /* CFBundleDevelopmentRegion = en; CFBundleExecutable = DeviceInfo; CFBundleIdentifier = "arbboter.com.DeviceInfo"; CFBundleInfoDictionaryVersion = "6.0"; CFBundleInfoPlistURL = "Info.plist -- file:///../DeviceInfo.app/"; CFBundleName = DeviceInfo; CFBundleNumericVersion = 16809984; CFBundlePackageType = APPL; CFBundleShortVersionString = "1.0"; CFBundleSignature = "????"; CFBundleSupportedPlatforms = ( iPhoneSimulator ); CFBundleVersion = 1; DTPlatformName = iphonesimulator; DTSDKName = "iphonesimulator8.1"; LSRequiresIPhoneOS = 1; UIDeviceFamily = ( 1 ); UILaunchStoryboardName = LaunchScreen; UIMainStoryboardFile = Main; UIRequiredDeviceCapabilities = ( armv7 ); UISupportedInterfaceOrientations = ( UIInterfaceOrientationPortrait, UIInterfaceOrientationLandscapeLeft, UIInterfaceOrientationLandscapeRight ); */ }
IOS获取设备信息
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。