简体   繁体   中英

How to find whether iphone device connected to 3G /Wifi using Reachability

Can any one get me idea to find whether iphone device connected to 3G /Wifi using Reachability.kindly get me some samples / URL's .im new in this iphone development.

Thanks in advance

您可以尝试从Apple http://developer.apple.com/iphone/library/samplecode/Reachability/的Rechability示例开始

firstly add SystemConfiguration.framework to your project

//Class.h
#import "Reachability.h"
#import <SystemConfiguration/SystemConfiguration.h>

- (BOOL)connected;

//Class.m

- (BOOL)connected
{
    Reachability *reachability = [Reachability reachabilityForInternetConnection];
    NetworkStatus networkStatus = [reachability currentReachabilityStatus];
    return networkStatus != NotReachable;
}
Then, I use this whenever I want to see if I have a connection:

if (![self connected]) {
    // Not connected
} else {
    // Connected. Do some Internet stuff
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM