开发者

Objective C: Unable to obtain Network Status value

I am trying to get the network status via the following code

//define in my .h file
NetworkStatus internetConnectionStatus;

//define in my .m file
self.internetConnectionStatus = [[Reachability reachabilityForInternetConnection]currentReachabilityStatus];

I am getting self.internetconnection status = <null>开发者_StackOverflow社区. What am I doing wrong here?


You should compare the value of it to the enum values defined in Reachability.h:

if(self.internetConnectionStatus == NotReachable)
{
    // no connection
} else if(self.internetConnectionStatus == ReachableViaWiFi)
{
    // WiFi connection
} else if(self.internetConnectionStatus == ReachableViaWWAN)
{
    // 3G connection
}

Also, make sure your NetworkStatus has an @property (nonatomic, assign) for it in your header if you're using self. to get/set it.

In my opinion though, assuming you're using the Apple Reachability sample, it's not particularly refined and could possibly be giving an erroneous value in some circumstances. For a more robust version, use either the version that ships with the ASIHTTPRequest library, or the version which it is based on, which is available for download here and detailed in this blog post.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜