1.获取设备信息
UIDevice*device = [[UIDevicealloc]init];
NSString*name = device.name;//获取设备用户的名称
NSString*model = device.model;//获取设备的类别
NSString*localizedModel = device.localizedModel;//地方型号 (国际化区域名称)
NSString*systemName = device.systemName;//获取当前运行的系统
NSString*systemVersion = device.systemVersion;//获取当前系统的版本
NSString*UUID = device.identifierForVendor.UUIDString;//获取设备的UUID唯一标示符
NSLog(@"\n name:%@\n model:%@\n localizedModel:%@\n systemName:%@\n systemVersion:%@\n",name,model,localizedModel,systemName,systemVersion);
NSLog(@"\n UUID:%@",UUID);
//设备朝向
NSLog(@"设备朝向 - %ld", (long)device.orientation);
// 当前设备是否有转向通知
NSLog(@"设备转向通知 BOOL- %d", device.generatesDeviceOrientationNotifications);
// 是否启动电池监控,默认为NO
NSLog(@"电池监控启用状态 BOOL- %d", device.batteryMonitoringEnabled);
//用户界面模式
NSLog(@"用户界面模式 - %ld", (long)device.userInterfaceIdiom);
NSDictionary*infoDict =[[NSBundlemainBundle]infoDictionary];
NSString*versionNum =[infoDictobjectForKey:@"CFBundleVersion"];//当前应用版本号码
NSString*appName =[infoDictobjectForKey:@"CFBundleDisplayName"];//当前应用名称
NSString*appCurVersion = [infoDictobjectForKey:@"CFBundleShortVersionString"];//当前应用软件版本
2.获取当前屏幕分辨率的信息 屏幕长宽
CGRect rect = [[UIScreenmainScreen]bounds];
CGFloat scale = [[UIScreenmainScreen]scale];
CGFloat width = rect.size.width* scale;
CGFloat height = rect.size.height* scale;
NSLog(@"分辨率\n width:%f\n height:%f",width,height);
floatscreenHeight = [UIScreenmainScreen].bounds.size.height;
floatscreenWidth = [UIScreenmainScreen].bounds.size.width;
NSLog(@"屏幕\n width:%f\n height:%f",screenWidth,screenHeight);
3.设备震动
/*
需要加入AudioToolbox framework,
导入头文件 #import
在需要震动的地方写下面的代码即可
*/
AudioServicesPlaySystemSound (kSystemSoundID_Vibrate);
4.获取电池的相关信息
//获取电池当前的状态
NSLog(@"电池当前状态:%@",[selfgetBatteryState]);
//获取电量的等级,0.00~1.00
NSLog(@"获取电量等级:%f",[selfgetBatteryLevel]);
//方法
//获取电池当前的状态,共有4种状态
-(NSString*) getBatteryState {
UIDevice*device = [UIDevicecurrentDevice];
if(device.batteryState== UIDeviceBatteryStateUnknown) {
return@"UnKnow未知";
}elseif(device.batteryState== UIDeviceBatteryStateUnplugged){
return@"Unplugged电源已拔开";
}elseif(device.batteryState== UIDeviceBatteryStateCharging){
return@"Charging充电";
}elseif(device.batteryState== UIDeviceBatteryStateFull){
return@"Full充满";
}
returnnil;
}
//获取电量的等级,0.00~1.00
-(float) getBatteryLevel {
return[UIDevicecurrentDevice].batteryLevel;
}
5.获取运营商的信息
/*需导入
#import
#import
*/
CTTelephonyNetworkInfo*info = [[CTTelephonyNetworkInfoalloc]init];
//获取运行商名称
CTCarrier*carrier = [infosubscriberCellularProvider];
NSString*mCarrier = [NSStringstringWithFormat:@"%@",[carriercarrierName]];
//获取网络类型
NSString*mConnectType = [[NSStringalloc]initWithFormat:@"%@",info.currentRadioAccessTechnology];
NSLog(@"运行商:%@",mCarrier);
NSLog(@"网络类型:%@",mConnectType);
/*网络类型
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
*/
6.网络状态监听
/*导入
系统库SystemConfiguration.framework
第三方Reachability.h
*/
Reachability*reach = [ReachabilityreachabilityWithHostName:@"www.baidu.com"];
switch([reachcurrentReachabilityStatus])
{
caseNotReachable://未连接
NSLog(@"网络未连接");
break;
caseReachableViaWiFi://通过wifi连接
NSLog(@"wifi");
break;
caseReachableViaWWAN://通过GPRS连接
NSLog(@"CPRS");
break;
default://未知情况
break;
}
本文Demo:http://download.csdn.net/detail/jackjia2015/9435384
转载自:http://blog.csdn.net/jackjia2015/article/details/50685536
网友评论