iOS 设备信息获取

參考:http://blog.csdn.net/decajes/article/details/41807977
參考:http://zengrong.net/post/2152.htm
1. 获取设备的信息
    UIDevice *device = [[UIDevice alloc] init];
    NSString *name = device.name;
    NSString *model = device.model; // 设备类型。比方是苹果还是itouch
    NSString *type = device.localizedModel; // 获取本地化版本号
    NSString *systemName = device.systemName; // 当前执行系统的名称
    NSString *systemVersion = device.systemVersion; //获取当前系统的版本号


    
    NSLog(@"%@-%@-%@-%@-%@",name,model,type,systemName,systemVersion);
    //iPhone Simulator-iPhone Simulator-iPhone Simulator-iPhone OS-8.1


2. 获取设备的唯一标识符(UDID)
    NSString *identifier = [[[UIDevice currentDevice] identifierForVendor] UUIDString];


3.获取当前屏幕分辨率的信息
    CGRect rect = [UIScreen mainScreen].bounds;
    CGFloat scale = [UIScreen mainScreen].scale;
    CGFloat width = rect.size.width * scale;
    CGFloat height = rect.size.height * scale;


4. 获取运营商的信息 
#import <CoreTelephony/CTCarrier.h>
#import <CoreTelephony/CTTelephonyNetworkInfo.h>


    CTTelephonyNetworkInfo *info = [[CTTelephonyNetworkInfo alloc] init];
    CTCarrier *carrier = [info subscriberCellularProvider];
    NSString *mCarrier = [NSString stringWithFormat:@"%@",[carrier carrierName]]; // 获取运营商的名称
    
    NSString *mConnectType = [NSString stringWithFormat:@"%@",info.currentRadioAccessTechnology]; // 获取当前网络类型


5. 加入震动


#import <AudioToolbox/AudioToolbox.h>
    AudioServicesPlayAlertSound(kSystemSoundID_Vibrate); // 加入震动
可是貌似这个不支持传入震动时间和模式。


6. 获取电池的相关信息
@implementation BatterMonitor
//获取电池当前的状态,共同拥有4种状态
-(NSString*) getBatteryState {  
    UIDevice *device = [UIDevice currentDevice];  
    if (device.batteryState == UIDeviceBatteryStateUnknown) {  
        return @"UnKnow";  
    }else if (device.batteryState == UIDeviceBatteryStateUnplugged){  
        return @"Unplugged";  
    }else if (device.batteryState == UIDeviceBatteryStateCharging){  
        return @"Charging";  
    }else if (device.batteryState == UIDeviceBatteryStateFull){  
        return @"Full";  
    }
return nil;

//获取电量的等级。0.00~1.00
-(float) getBatteryLevel {  
return [UIDevice currentDevice].batteryLevel;



-(void) getBatteryInfo
{
NSString *state = getBatteryState();
float level = getBatteryLevel()*100.0;
//yourControlFunc(state, level);  //写自己要实现的获取电量信息后怎么处理
}


//打开对电量和电池状态的监控,类似定时器的功能
-(void) didLoad
{
[[UIDevice currentDevice] setBatteryMonitoringEnable:YES];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(getBatteryInfo:) name:UIDeviceBatteryStateDidChangeNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(getBatteryInfo:) name:UIDeviceBatteryLevelDidChangeNotification object:nil];
[NSTimer scheduledTimerWithTimeInterval:0.5f target:self selector:@selector(getBatteryInfo:) userInfo:nil repeats:YES];
}
@end


7. app中打开一个网页
NSString *url = @"www.apple.com"
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];


8. app中打开还有一个app
打开还有一个app还是能够通过openURL来实现。可是要分两种情况。
第一种是启动内置的应用,一般的电话,浏览器。短信和邮件能够直接调用并加入參数。譬如:


[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel://10086"]];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"mailto://devprograms@apple.com"]];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"sms://10086"]];


另外一种情况是要打开自己开发的app。这样的情况则要为将要打开的app注冊一个URL协议。这个能够在项目的文件info.plist中注冊。主要操作为:


Step1. 右键。选择“Add Row”


Step2. Key值选择“URL types”


Step3. 打开“Item 0″,然后为该key添加一个URL identifier。能够是不论什么值,但建议用“反域名”(比如 “com.fcplayer.testHello”)。




Step4. 在“Item 0”下再加一行。




Step5. 选择“URL Schemes” 作为Key。


Step6. 输入你的URL协议名 (比如“testHello://” 应写做“testHello”)。

假设有必要,你能够在这里增加多个协议。




事实上在打开的时候仅仅须要URL Schemes就可以,URL identifier是可选项。

假设须要传送參数。能够在URL Schemes://加入你的參数,格式和网页开发的传递參数几乎相同。(又或者URL Schemes://URL identifier@加入的參数)关键是要和接收參数方定义优点理的方式。

然后在须要打开的地方加入代码:


NSString *url = @"URL Schemes的路径"
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];

原文地址:https://www.cnblogs.com/zhchoutai/p/6734679.html