mirror of
https://github.com/wu736139669/SmallGame_Cocos2dx.git
synced 2026-08-05 06:23:09 +00:00
55 lines
1.2 KiB
Plaintext
55 lines
1.2 KiB
Plaintext
//
|
|
// JudgeNetEnvironment.cpp
|
|
// OnceAgain
|
|
//
|
|
// Created by xiaoqiang on 14-5-26.
|
|
//
|
|
//
|
|
|
|
#include "JudgeNetEnvironment.h"
|
|
//#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] == ReachableViaWiFi);
|
|
}
|
|
|
|
// 检测3G网络是否可用
|
|
bool is3GEnabled()
|
|
{
|
|
return ([[Reachability reachabilityForInternetConnection]currentReachabilityStatus] == ReachableViaWWAN);
|
|
}
|
|
|
|
|
|
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;
|
|
}
|
|
|
|
}
|
|
|
|
|