获取 ios 系统网络状况、电量
来源:互联网 发布:瓷砖设计软件手机版 编辑:程序博客网 时间:2024/04/30 10:13
本篇博客出自阿修罗道,转载请注明出处:http://blog.csdn.net/fansongy/article/details/8927734
cocos2d-x中并没有关于获取一些系统底层信息的方法。由于跨平台编译的原因,需要根据平台来自己写。
通常需要显示是网络连接状态和电池的电量这两个。
#import "Foundation/Foundation.h"#import "UIKit/UIKit.h"typedef enum{// Apple NetworkStatus Compatible Names.NoNetWork = 0,ConnWiFi = 2,Conn3G = 1} NetState;// 获取电池电量,范围0到1.0。-1表示电量未知。float getBatteryLeve();// 检测WIFI是否可用bool isWIFIEnabled();// 检测3G网络是否可用bool is3GEnabled();//取得网络连接状况NetState getNetState();
实现是用.mm来实现,就是调用一些ios现成的接口。
#include "SystemInfo.h"#import "Reachability.h"NSString* testPage = @"www.baidu.com";float getBatteryLeve(){ [[UIDevice currentDevice] setBatteryMonitoringEnabled:YES]; return [[UIDevice currentDevice] batteryLevel];}// 检测WIFI是否可用bool isWIFIEnabled(){ return ([[Reachability reachabilityForLocalWiFi] currentReachabilityStatus] != NotReachable);}// 检测3G网络是否可用bool is3GEnabled(){ return [[Reachability reachabilityForInternetConnection] isReachableViaWWAN];}NetState getNetState(){ Reachability *r = [Reachability reachabilityWithHostname:testPage]; switch ([r currentReachabilityStatus]) { case NotReachable: // 没有网络连接 return NoNetWork; break; case ReachableViaWWAN: // 使用3G网络 return Conn3G; break; case ReachableViaWiFi: // 使用WiFi网络 return ConnWiFi; break; } }
其中Reachability类是官方给提供的一个测试网络的类。使用时引入Reachability.h 和.m就可以,另外还要在Frameworks中加入SystemConfiguration.framework。一些使用可以百度,我下面的源码中也能找到相应的项目。
源码:http://download.csdn.net/detail/fansongy/5377491
- 获取 ios 系统网络状况、电量
- 获取 ios 系统网络状况、电量
- 判断IOS的网络和电量状况
- Unity&Android之二:获取手机电量信息、网络状况
- Unity IOS获取电量和网络类型
- 获取ios设备电量
- 获取ios设备电量
- iOS 获取剩余电量
- android 获取系统电量
- 获取系统电量
- iOS判断网络状况
- iOS开发-获取设备电量
- 获取Windows网络连接状况
- iOS实时监测网络状况
- iOS 状态栏数据获取(服务商,网络状态,信号,电量,IP,WiFi)
- Unity获取手机电量 网络和时间
- 如何获取网络延迟,手机电量
- linux c 实现 获取系统内存,某进程cpu利用率,以及某端口的网络状况
- 堆 和 栈的 区别
- 大整数乘法
- 数据结构——链表的操作
- hdu1542线段树+离散化+扫描线详解
- 高效工作——EA使用技巧
- 获取 ios 系统网络状况、电量
- Myeclipse8.5激活工具
- hdu 1060 Leftmost Digit
- 循环buffer解决网络通信中数据的不完整接收
- Android性能优化案例研究(下)
- ubuntu防火墙设置
- 好的学习网站http://doc.lastme.com/
- request.getParamete与request.getAttribute的用法
- UITableViewCell自定义accessoryView,通过tag避免因为Cell重用导致的button状态重复