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