[首页]
[文章]
[教程]
首页
Web开发
Windows开发
编程语言
数据库技术
移动平台
系统服务
微信
设计
布布扣
其他
数据分析
首页
>
移动平台
> 详细
iOS 设备信息获取
时间:
2015-07-23 23:57:20
阅读:
402
评论:
0
收藏:
0
[点我收藏+]
参考:
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]];
版权声明:本文为博主原创文章,未经博主允许不得转载。
iOS 设备信息获取
原文:http://blog.csdn.net/linfengwenyou/article/details/47029229
踩
(
0
)
赞
(
0
)
举报
评论
一句话评论(
0
)
登录后才能评论!
分享档案
更多>
2021年09月23日 (328)
2021年09月24日 (313)
2021年09月17日 (191)
2021年09月15日 (369)
2021年09月16日 (411)
2021年09月13日 (439)
2021年09月11日 (398)
2021年09月12日 (393)
2021年09月10日 (160)
2021年09月08日 (222)
最新文章
更多>
2021/09/28 scripts
2022-05-27
vue自定义全局指令v-emoji限制input输入表情和特殊字符
2022-05-27
9.26学习总结
2022-05-27
vim操作
2022-05-27
深入理解计算机基础 第三章
2022-05-27
C++ string 作为形参与引用传递(转)
2022-05-27
python 加解密
2022-05-27
JavaScript-对象数组里根据id获取name,对象可能有children属性
2022-05-27
SQL语句——保持现有内容在后面增加内容
2022-05-27
virsh命令文档
2022-05-27
教程昨日排行
更多>
1.
list.reverse()
2.
Django Admin 管理工具
3.
AppML 案例模型
4.
HTML 标签列表(功能排序)
5.
HTML 颜色名
6.
HTML 语言代码
7.
jQuery 事件
8.
jEasyUI 创建分割按钮
9.
jEasyUI 创建复杂布局
10.
jEasyUI 创建简单窗口
友情链接
汇智网
PHP教程
插件网
关于我们
-
联系我们
-
留言反馈
- 联系我们:wmxa8@hotmail.com
© 2014
bubuko.com
版权所有
打开技术之扣,分享程序人生!