在iOS(跨平台C ++库解决方案)中构建错误,同时使用可访问性框架来检测网络接口类型

时间:2014-09-03 06:41:52

标签: c++ ios objective-c reachability

我正在尝试使用此处给出的代码Reachability sample code。但是我面临着一些问题。要使用我从here下载的Reachability.h和Reachability.m代码。但每当我尝试编译时,它都无法识别 Reachability类。导致问题的代码块如下所示 -

Reachability *reachability = [Reachability reachabilityForInternetConnection]; // in this line it doesn't recognize "Reachability"
[reachability startNotifier];

NetworkStatus status = [reachability currentReachabilityStatus]; // In this line it doesn't recognize "NetworkStatus"

if(status == NotReachable) 
{
    //No internet
}
else if (status == ReachableViaWiFi)
{
    //WiFi
}
else if (status == ReachableViaWWAN) 
{
    //3G
}

请注意我在跨平台C ++库解决方案的iOS块中使用此代码。我需要尽快解决这个问题。我正在寻求帮助来解决这个问题?

编辑:

在为 OBJC 宏添加条件检查后,

解决了构建错误。但似乎代码没有编译。这是编辑过的代码

#ifdef __OBJC__

Reachability *reachability = [Reachability reachabilityForInternetConnection];
[reachability startNotifier];

NetworkStatus status = [reachability currentReachabilityStatus];

if(status == NotReachable) 
{
    //No internet
}
else if (status == ReachableViaWiFi)
{
    //WiFi
}
else if (status == ReachableViaWWAN) 
{
    //3G
}
#endif

我想使用上面的代码,也想编译代码。怎么做?

1 个答案:

答案 0 :(得分:0)

问题已解决。我已经使用Reachability框架的核心代码解决了这个问题。如果有人面临同样的问题,我可以提供帮助。

问题出现了,因为“NotReachable”,“ReachableViaWifi”和“ReachableViaWWAN”是用户定义的枚举。它不包含在“Rechability.h”中。所以,我已经下载了一个关于Reachability框架的项目,并找出这些值的真实系统标志。并解决了这个问题。