iOS 获取设备信息
来源:互联网 发布:单片机题库及答案 编辑:程序博客网 时间:2024/05/16 07:01
一、代码
//// 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检测网络状态
0 0
- 获取ios设备信息
- ios 获取设备信息
- 获取iOS设备信息
- IOS获取设备信息
- iOS获取设备信息
- 获取iOS设备信息
- 获取iOS设备信息
- iOS 设备信息获取
- iOS 获取设备信息
- iOS 获取设备信息
- iOS获取设备信息
- ios获取设备信息
- 获取iOS设备信息
- ios获取设备信息
- iOS 获取设备信息
- IOS 获取设备信息
- iOS 获取设备信息
- iOS 获取设备信息
- 第九周项目三—人数的不定工资
- 【56】java本地文件File类详解
- Cookie已经过时,细看Facebook, Google, Apple如何追踪用户
- 【转】中国历史上下五千年之朝代变迁
- 如何将.sql文件导入数据库
- iOS 获取设备信息
- 欢迎使用CSDN-markdown编辑器
- leetcode笔记--Valid Anagram
- 回文数判断
- android--乐学成语--------复制数据库,测试数据库
- 面试题:将一个字符串数组中的字母按照以下规则排列:表中任何单词的首字母与其前面单词的尾字母相同! 要求:字符串只由小写字母构成,且每个字符串长度在2-100之间
- 自然连接
- Raspberry Pi 2无线路由器配置
- 图片的align属性