iOS 获取设备信息
2023-09-11 14:22:56 时间
一、代码
//
// 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设备中垂直同步开启后的帧率计数
- [ IOS ] iOS-控制器View的创建和生命周期
- 判断不同IOS设备
- Unity3D研究院之IOS全自动打包生成ipa
- 获取IOS 设备基本信息
- ios之UIScrollerView滚动视图
- 获取iOS设备当前ip地址
- IOS 30多个iOS常用动画,带详细注释
- 【iOS开发】30多个iOS常用动画,带详细注释
- 三步教你iOS导入.ttf字体文件
- iOS之UI--关于modal
- 最详细在Windows安装Xamarin.iOS教程
- 【Swift】iOS开发历险记(二)
- safari 调试 打印刚加载界面时缓存的log信息 iOS Safari调试iPhone设备上的网页
- ios swift Data sha256加密
- iOS 逆向 越狱 砸壳 获取
- ios 蓝牙 扫描到蓝牙设备的时候同时记录advertisementData和RSSI
- IOS(swift)获取storyboard中的控制器(控制器设置)
- cordova(android ios) ota给蓝牙设备升级
- Ios开发之 -- js和ios的交互
- 奔五的人学ios:swift竟然没有字符串包括,找个简单的解决方法
- iOS操作系统