iOS 获取设备信息
2016-06-11 17:04
609 查看
一、代码
二、运行截图
由于在<CoreTelephony/CTelephonyNetwork.h>中没有找到wifi有关的判断,所以Reachability获取现在还是必要的,这方面可以参考我的另一篇博文iOS Reachability检测网络状态
// // ViewController.m // DeviceInfoDemo // // Created by 555chy on 6/11/16. // Copyright © 2016 555chy. All rights reserved. // #import "ViewController.h" #import <CoreTelephony/CTCarrier.h> #import <CoreTelephony/CTTelephonyNetworkInfo.h> @interface ViewController () @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. //获取设备的基本信息 UIDevice *device = [UIDevice currentDevice]; NSLog(@"device.name %@", device.name); NSLog(@"device.model %@", device.model); NSLog(@"device.localizedModel %@", device.localizedModel); NSLog(@"device.systemName %@", device.systemName); NSLog(@"device.systemVersion %@", device.systemVersion); NSLog(@"device.identifierForVendor %@", [device.identifierForVendor UUIDString]); //电池状态 /* typedef NS_ENUM(NSInteger, UIDeviceBatteryState) { UIDeviceBatteryStateUnknown, UIDeviceBatteryStateUnplugged, // on battery, discharging UIDeviceBatteryStateCharging, // plugged in, less than 100% UIDeviceBatteryStateFull, // plugged in, at 100% }; // available in iPhone 3.0 */ NSLog(@"device.batteryState %ld", device.batteryState); //电池电量级别(0 .. 1.0. -1.0 if UIDeviceBatteryStateUnknown) NSLog(@"device.batteryLevel %f", device.batteryLevel); /* 屏幕朝向,如果没有开启自动旋转的话就是unknown typedef NS_ENUM(NSInteger, UIDeviceOrientation) { UIDeviceOrientationUnknown, UIDeviceOrientationPortrait, // Device oriented vertically, home button on the bottom UIDeviceOrientationPortraitUpsideDown, // Device oriented vertically, home button on the top UIDeviceOrientationLandscapeLeft, // Device oriented horizontally, home button on the right UIDeviceOrientationLandscapeRight, // Device oriented horizontally, home button on the left UIDeviceOrientationFaceUp, // Device oriented flat, face up UIDeviceOrientationFaceDown // Device oriented flat, face down }; */ NSLog(@"device.orientation %ld", device.orientation); //获取屏幕分辨率 CGRect rect = [[UIScreen mainScreen] bounds]; CGFloat screenScale = [UIScreen mainScreen].scale; CGFloat screenWidth = rect.size.width * screenScale; CGFloat screenHeight = rect.size.height * screenScale; NSLog(@"screen scale %f", screenScale); NSLog(@"screen size %f * %f", screenWidth, screenHeight); //获取运营商信息(需要引用如下2个头文件) //#import <CoreTelephony/CTCarrier.h> //#import <CoreTelephony/CTTelephonyNetworkInfo.h> CTTelephonyNetworkInfo *networkInfo = [[CTTelephonyNetworkInfo alloc] init]; CTCarrier *carrier = [networkInfo subscriberCellularProvider]; NSLog(@"carrier.carrierName %@", carrier.carrierName); //IOS7之前apple给我们提供了Reachability来获取,IOS7后可以通过以下方式来获取,方便而且类型更多 /* CTRadioAccessTechnologyGPRS //介于2G和3G之间,也叫2.5G ,过度技术 CTRadioAccessTechnologyEdge //EDGE为GPRS到第三代移动通信的过渡,EDGE俗称2.75G CTRadioAccessTechnologyWCDMA CTRadioAccessTechnologyHSDPA //亦称为3.5G(3?G) CTRadioAccessTechnologyHSUPA //3G到4G的过度技术 CTRadioAccessTechnologyCDMA1x //3G CTRadioAccessTechnologyCDMAEVDORev0//3G标准 CTRadioAccessTechnologyCDMAEVDORevA CTRadioAccessTechnologyCDMAEVDORevB CTRadioAccessTechnologyeHRPD //电信使用的一种3G到4G的演进技术, 3.75G CTRadioAccessTechnologyLTE //接近4G */ NSLog(@"networkInfo.currentRadioAccessTechnology %@", networkInfo.currentRadioAccessTechnology); } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end
二、运行截图
由于在<CoreTelephony/CTelephonyNetwork.h>中没有找到wifi有关的判断,所以Reachability获取现在还是必要的,这方面可以参考我的另一篇博文iOS Reachability检测网络状态
相关文章推荐
- iOS CocoaPods的使用
- ARM汇编基础(iOS逆向)
- 图片拉伸
- 基本输入输出系统BIOS
- iOS开发多线程篇—多线程简单介绍
- 【IOS】Instruments 使用教程
- iOS视频录制、压缩导出、取帧
- nagios安装
- 不得姐实战教程 02 配置tabbar
- Xcode各版本官方下载及百度云盘下载, Mac和IOS及Xcode版本历史.
- iOS给工程中选中的文件创建分组文件夹(小技巧)
- 技术博客的重要性
- iOS9新增关键字和一些新特性
- iOS 解决button设置背景图片的时候拉伸变形的问题
- iOS 应用发布流程
- iOS支付宝支付
- iOS构建用户界面
- IOS地图开发及定位
- iOS手动加载控制器xib与指定加载控制器xib的情况分析
- iOS控制器的懒加载lazyLoadController