如何使用Reachability查找iphone设备是否连接到3G / Wifi

时间:2010-12-23 03:52:03

标签: iphone ipad wifi reachability

任何人都可以通过Reachability让我知道iphone设备是否连接到3G / Wifi。在这款iphone开发中,我可以获得一些示例/ URL的.im新内容。

提前致谢

2 个答案:

答案 0 :(得分:1)

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

答案 1 :(得分:0)

首先将SystemConfiguration.framework添加到您的项目

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