028-86922220

建站动态

根据您的个性需求进行定制 先人一步 抢占小程序红利时代

reachabilityios网络连接判断-创新互联

reachability ios网络连接判断

创新互联公司是专业的蒙自网站建设公司,蒙自接单;提供网站设计、成都网站建设,网页设计,网站设计,建网站,PHP网站建设等专业做网站服务;采用PHP框架,可快速的进行蒙自网站开发网页制作和功能扩展;专业做搜索引擎喜爱的网站,专业的做网站团队,希望更多企业前来合作!

//Reachability.h

import 

import 

typedef enum { NotReachable = 0, ReachableViaWiFi, ReachableViaWWAN } NetworkStatus;

define kReachabilityChangedNotification @"kNetworkReachabilityChangedNotification"

@interface Reachability: NSObject { BOOL localWiFiRef; SCNetworkReachabilityRef reachabilityRef; }

//reachabilityWithHostName- Use to check the reachability of a particular host name.

//reachabilityWithAddress- Use to check the reachability of a particular IP address.

//reachabilityForInternetConnection- checks whether the default route is available.
// Should be used by applications that do not connect to a particular host

//reachabilityForLocalWiFi- checks whether a local wifi connection is available.

//Start listening for reachability notifications on the current run loop

//Reachability.m

import 

import 

import 

import 

import 

import 

import 

import "Reachability.h"

define kShouldPrintReachabilityFlags 1

static void PrintReachabilityFlags(SCNetworkReachabilityFlags flags, const char* comment) {

if kShouldPrintReachabilityFlags

NSLog(@"Reachability Flag Status: %c%c %c%c%c%c%c%c%c %s\n",
        (flags & kSCNetworkReachabilityFlagsIsWWAN)                  ? 'W' : '-',
        (flags & kSCNetworkReachabilityFlagsReachable)            ? 'R' : '-',

        (flags & kSCNetworkReachabilityFlagsTransientConnection)  ? 't' : '-',
        (flags & kSCNetworkReachabilityFlagsConnectionRequired)   ? 'c' : '-',
        (flags & kSCNetworkReachabilityFlagsConnectionOnTraffic)  ? 'C' : '-',
        (flags & kSCNetworkReachabilityFlagsInterventionRequired) ? 'i' : '-',
        (flags & kSCNetworkReachabilityFlagsConnectionOnDemand)   ? 'D' : '-',
        (flags & kSCNetworkReachabilityFlagsIsLocalAddress)       ? 'l' : '-',
        (flags & kSCNetworkReachabilityFlagsIsDirect)             ? 'd' : '-',
        comment
        );

endif

}

@implementation Reachability static void ReachabilityCallback(SCNetworkReachabilityRef target, SCNetworkReachabilityFlags flags, void* info) {

pragma unused (target, flags)

NSCAssert(info != NULL, @"info was NULL in ReachabilityCallback");
NSCAssert([(NSObject*) info isKindOfClass: [Reachability class]], @"info was wrong class in ReachabilityCallback");//We're on the main RunLoop, so an NSAutoreleasePool is not necessary, but is added defensively// in case someon uses the Reachablity object in a different thread.NSAutoreleasePool* myPool = [[NSAutoreleasePool alloc] init];

Reachability* noteObject = (Reachability*) info;// Post a notification to notify the client that the network reachability changed.[[NSNotificationCenter defaultCenter] postNotificationName: kReachabilityChangedNotification object: noteObject];

[myPool release];

}

pragma mark Network Flag Handling

//appcontroller

//网络状态改变

} -(void) updateInterfaceWithReachability:(Reachability*) curReach { NetworkStatus netStatus = [curReach currentReachabilityStatus]; //BOOL connectionRequired= [curReach connectionRequired]; if(firstComeIn){ firstComeIn=false; return; } switch (netStatus) { case NotReachable: //没有连接 {

        break;
    }    case ReachableViaWWAN: //3g/GPRS
    {        break;
    }    case ReachableViaWiFi:  //wifi
    {        break;
    }
}

另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


本文标题:reachabilityios网络连接判断-创新互联
网站网址:http://www.tsicrk.com/article/hpioo.html

其他资讯

让你的专属顾问为你服务

0.6762s