您可能希望通过使用 dlfcn.h 库来使用 Apple80211 私有框架。可以在此处找到一个 iphone 示例:
http://www.csse.uwa.edu.au/~chris/iphone/APlogger/
下载源文件并研究扫描仪模块。
总之,你会想出这样的事情:
#define IF_NAME "en0"
#include <dlfcn.h>
- (void)performScan
{
int (*open)(void *);
int (*bind)(void *, NSString *);
int (*close)(void *);
int (*scan)(void *, NSArray **, void *);
void *libHandle;
void *airportHandle;
libHandle = dlopen("/System/Library/Frameworks/Preferences.framework/Preferences", RTLD_LAZY);
open = dlsym(libHandle, "Apple80211Open");
bind = dlsym(libHandle, "Apple80211BindToInterface");
scan = dlsym(libHandle, "Apple80211Scan");
close = dlsym(libHandle, "Apple80211Close");
open(&airportHandle);
bind(airportHandle, @IF_NAME);
NSArray *found;
NSDictionary *params = [[NSDictionary alloc] init];
scan(airportHandle, &found, params);
int nnw = [found count];
for(int i=0 ; i < nnw ; i++) {
NSDictionary *nw = [found objectAtIndex:i];
NSString *ssid = [self fixSSID:nw];
// RSSI indicates signal strength
int rssi = [[nw objectForKey:@"RSSI"] intValue];
}
// Cleanup
close(airportHandle);
dlclose(libHandle);
}
-(NSString *)fixSSID:(NSDictionary *)nw
{
if ([[nw objectForKey:@"HIDDEN_NETWORK"] boolValue])
return @"<hidden>";
else
return [nw objectForKey:@"SSID_STR"];
}
请注意,如果您在 iOS 应用程序中使用私有框架,您将无法在 App Store 上发布它们(Apple 将拒绝您的应用程序,因为没有 Apple80211 框架的公开文档)。但由于您的问题是关于 OSX 开发的,因此这不适用于您的情况。
希望能帮助到你。