iOS 设备信息获取
參考:http://blog.csdn.net/decajes/article/details/41807977參考:http://zengrong.net/post/2152.htm1. 获取设备的信息
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]];
iOS 设备信息获取的更多相关文章
- iOS开发的另类神器:libimobiledevice开源包【类似android adb 方便获取iOS设备信息】
简介 libimobiledevice又称libiphone,是一个开源包,可以让Linux支持连接iPhone/iPod Touch等iOS设备.由于苹果官方并不支持Linux系统,但是Linux上 ...
- 史上最全的iOS各种设备信息获取总结
来源:si1ence 链接:http://www.jianshu.com/p/b23016bb97af 为了统计用户信息.下发广告,服务器端往往需要手机用户设备及app的各种信息,下面讲述一下各种信息 ...
- iOS: iOS各种设备信息获取
Author:si1ence Link:http://www.jianshu.com/p/b23016bb97af 为了统计用户信息.下发广告,服务器端往往需要手机用户设备及app的各种信息,下面讲述 ...
- 整理UWP中网络和设备信息获取的帮助类,需要的拿走。
网络(运营商信息,网络类型) public static class NetworkInfo { /// <summary> /// 网络是否可用 /// </summary> ...
- IOS设备 UIDevice 获取操作系统 版本 电量 临近手机触发消息检测 (真机亲测可用)
- (void)viewDidLoad { [super viewDidLoad]; // 操作系统 NSString * osName =[[UIDevice currentDevice]syste ...
- 获取iOS设备信息的编程接口
参考资料: [1] 博客园,iOS屏幕尺寸和分辨率了解 [2] 张兴业,获取手机信息(UIDevice.NSBundle.NSLocale), CSDN
- 获取iOS设备信息(内存/电量/容量/型号/IP地址/当前WIFI名称)
1.获取电池电量(一般用百分数表示,大家自行处理就好) 1 2 3 4 -(CGFloat)getBatteryQuantity { return [[UIDevice current ...
- 获取设备信息——获取客户端ip地址和mac地址
1.获取本地IP(有可能是 内网IP,192.168.xxx.xxx) /** * 获取本地IP * * @return */ public static String getLocalIpAddre ...
- IOS 设备信息读取
let infoDictionary = NSBundle.mainBundle().infoDictionary let appDisplayName: AnyObject? = infoDicti ...
随机推荐
- css特效-一道闪光在图片上划过
在百度音乐 http://music.baidu.com/ 看到这么一个图片效果,当鼠标移上去的时候,会有一道闪光在图片上划过,效果挺酷炫的.于是把这个效果再实现一下:大体思想是,设计一个透明层i,s ...
- 八皇后--python代码
迭代和递归方法的运用 import random def prettyprint(solution): #图形化处理数据 def line(pos,length=len(solution)): #单行 ...
- 51nod1624 取余最长路 前缀和 + set
由于只有3行,因此只会会换行2次,假设$x, y$分别为这两次的换行点 那么答案为$S[1][x] +S[2][y] - S[2][x - 1] + S[3][n] - S[3][y - 1]$ 其中 ...
- noip200807传纸条
试题描述: 小渊和小轩是好朋友也是同班同学,他们在一起总有谈不完的话题.一次素质拓展活动中,班上同学安排做成一个m行n列的矩阵,而小渊和小轩被安排在矩阵对角线的两端,因此,他们就无法直接交谈了.幸运的 ...
- CROC 2016 - Elimination Round (Rated Unofficial Edition) A. Amity Assessment 水题
A. Amity Assessment 题目连接: http://www.codeforces.com/contest/655/problem/A Description Bessie the cow ...
- LT1961 升压型稳压器造就了兼具升压和降压能力的扁平状SEPIC
http://cds.linear.com/docs/cn/design-note/DN317%20sim_chs.pdf http://cds.linear.com/docs/en/datashee ...
- BUZZER Driver
- mysql 监控工具
zabbix和grafana是绝配. pmm的prometheus太占资源了
- zookeeper疑难杂症
1.zookeeper是怎么写数据的?因为是master写再同步广播到follow节点,如果master写完,following在写的过程中出现失败怎么办? :zookeeper支持原子的写入操作,要 ...
- Turn any Linux computer into SOCKS5 proxy in one command
src: http://www.catonmat.net/blog/linux-socks5-proxy/ I thought I'd do a shorter article on catonmat ...