开发者

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

Can any one get me idea t开发者_StackOverflow中文版o 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


You could try to start from the Rechability example from Apple http://developer.apple.com/iphone/library/samplecode/Reachability/


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
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜