123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- //
- // Util.m
- // Miaxis
- //
- // Created by tongjun on 14-3-5.
- // Copyright (c) 2014年 tongjun. All rights reserved.
- //
- #import "Util.h"
- #import <RealReachability/RealReachability.h>
- @implementation Util
- //判断网络是否连接
- + (BOOL) connectedToNetWork{
-
- [GLobalRealReachability startNotifier];
- ReachabilityStatus status = [GLobalRealReachability currentReachabilityStatus];
- [GLobalRealReachability stopNotifier];
- return status ? YES : NO;
-
- //需要确保该host地址可以被ping探测到。此操作为可选,默认的目标host地址为www.baidu.com
- //GLobalRealReachability.hostForPing = @"www.baidu.com";
- //手动设置自动探测间隔(autoCheckInterval,单位为分钟).此处根据应用的实时性要求来设置自动探测的间隔,实时性要求较高时可适当调低此参数,但不建议设置为1.0以下
- //GLobalRealReachability.autoCheckInterval = 2.0f;
-
- //----------------------------这一块先埋伏在这里吧-----------------------@lee
-
- // [GLobalRealReachability reachabilityWithBlock:^(ReachabilityStatus status)
- // {
-
- // switch (status)
- // {
- // case RealStatusUnknown:
- // {
- // //NSLog(@"Unknown");
- // break;
- // }
- //
- // case RealStatusNotReachable:
- // {
- // //NSLog(@"NotReachable");
- // break;
- // }
- //
- // case RealStatusViaWiFi:
- // {
- // //NSLog(@"wifi");
- // break;
- // }
- //
- // case RealStatusViaWWAN:
- // {
- // //NSLog(@"ViaWWAN");
- // WWANAccessType accessType = [GLobalRealReachability currentWWANtype];
- // if (accessType == WWANType2G)
- // {
- // //NSLog(@"RealReachabilityStatus2G");
- // }
- // else if (accessType == WWANType3G)
- // {
- // //NSLog(@"RealReachabilityStatus3G");
- // }
- // else if (accessType == WWANType4G)
- // {
- // //NSLog(@"RealReachabilityStatus4G");
- // }
- // else
- // {
- // //NSLog(@"Unknown RealReachability WWAN Status, might be iOS6");
- // }
- //
- //
- // break;
- // }
- // default:
- // break;
- // }
- // }];
- }
- +(NSString *)getAnswerByTen:(NSInteger)value
- {
- NSMutableString *string = [NSMutableString string];
- while (value)
- {
- [string insertString:(value & 1)? @"1": @"0" atIndex:0];
- value /= 2;
- }
- if (string.length==5) {
- string=[NSMutableString stringWithFormat:@"000%@",string];
- }else if(string.length==6){
- string=[NSMutableString stringWithFormat:@"00%@",string];
- }else if(string.length==7){
- string=[NSMutableString stringWithFormat:@"0%@",string];
- }else{
- string=string;
- }
- NSMutableString *answer=[[NSMutableString alloc]init];
- if (string.length >= 5) {
- if ([[string substringWithRange:NSMakeRange(3, 1)]intValue]==1) {
- [answer appendString:@"A"];
- }
- }
- if (string.length >= 4) {
- if ([[string substringWithRange:NSMakeRange(2, 1)]intValue]==1) {
- [answer appendString:@"B"];
- }
- }
- if (string.length >= 3) {
- if ([[string substringWithRange:NSMakeRange(1, 1)]intValue]==1) {
- [answer appendString:@"C"];
- }
- }
- if (string.length >= 2) {
- if ([[string substringWithRange:NSMakeRange(0, 1)]intValue]==1) {
- [answer appendString:@"D"];
- }
- }
- return [answer copy];
- }
- @end
|