2

我写了一个简单的函数,通过编译器而不是链接器。

知道为什么吗?

- (BOOL) connectedToWifi
{

    CFArrayRef myArray = CNCopySupportedInterfaces();
    // Get the dictionary containing the captive network infomation
    CFDictionaryRef captiveNtwrkDict = CNCopyCurrentNetworkInfo(CFArrayGetValueAtIndex(myArray, 0));

    NSLog(@"Information of the network we're connected to: %@", captiveNtwrkDict);

    NSDictionary *dict = (__bridge NSDictionary*) captiveNtwrkDict;
    NSString* ssid = [dict objectForKey:@"SSID"];

    if ([ssid rangeOfString:@"WXYZ"].location == NSNotFound || ssid == NULL)
    {
        return false;
    }
    else
    {
        return true;
    }
}

这是我得到的错误:

Undefined symbols for architecture i386:
  "_CNCopySupportedInterfaces", referenced from:
      -[miApp_funcs connectedToWifi] in miApp_funcs.o
  "_CNCopyCurrentNetworkInfo", referenced from:
      -[miApp_funcs connectedToWifi] in miApp_funcs.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
4

2 回答 2

4

以下是步骤-

1) 在导航区点击项目

2) 选择“目标”选项卡

3)点击“构建阶段”

4) 选择“将二进制文件与库链接”

5)然后您可以在该区域底部看到“+”按钮。您现在可以添加所需的 SystemConfiguration 框架。

#import <SystemConfiguration/SystemConfiguration.h>
于 2012-09-03T18:18:19.983 回答
3

您必须链接到 和#import <SystemConfiguration/SystemConfiguration.h>才能访问 Captive Network (CN) 类和函数。

于 2012-05-30T02:37:38.510 回答