我正在尝试读取iPhone连接到AP的WIFI信号强度(RSSI)。
我使用的是带有iOS 8.1.3的iPhone6+和Xcode 6.1.1。
下面的代码在iOS 8上崩溃,并在
这是一款非苹果商店应用——仅限于adhoc分发。
=================================================================
我使用的是带有iOS 8.1.3的iPhone6+和Xcode 6.1.1。
下面的代码在iOS 8上崩溃,并在
apple80211Open()
处出现EXC_BAD_ACCESS (code=1, address=0)
的错误。(该代码可在iOS 7.1上工作。)这是一款非苹果商店应用——仅限于adhoc分发。
=================================================================
void *libHandle;
void *airportHandle;
int (*apple80211Open)(void *);
int (*apple80211Bind)(void *, NSString *);
int (*apple80211Close)(void *);
int (*apple80211GetInfoCopy)(void *, CFDictionaryRef *);
NSMutableDictionary *infoDict = [NSMutableDictionary new];
NSDictionary * tempDictionary;
libHandle = dlopen("/System/Library/SystemConfiguration/IPConfiguration.bundle/IPConfiguration", RTLD_LAZY);
char *dlerror_error;
if (libHandle == NULL && (dlerror_error = dlerror()) != NULL) {
NSLog(@"%s", dlerror_error);
}
apple80211Open = dlsym(libHandle, "Apple80211Open");
apple80211Bind = dlsym(libHandle, "Apple80211BindToInterface");
apple80211Close = dlsym(libHandle, "Apple80211Close");
apple80211GetInfoCopy = dlsym(libHandle, "Apple80211GetInfoCopy");
apple80211Open(&airportHandle);
apple80211Bind(airportHandle, @"en0");
CFDictionaryRef info = NULL;
apple80211GetInfoCopy(airportHandle, &info);
tempDictionary = (__bridge NSDictionary *)info;
apple80211Close(airportHandle);
[infoDict setObject:(tempDictionary[@"RSSI"])[@"RSSI_CTL_AGR"] ? (tempDictionary[@"RSSI"])[@"RSSI_CTL_AGR"] : @"0" forKey:@"RSSI"];
[infoDict setObject:tempDictionary[@"BSSID"] ? tempDictionary[@"BSSID"] : @"null" forKey:@"BSSID"];
[infoDict setObject:tempDictionary[@"SSID_STR"] ? tempDictionary[@"SSID_STR"] : @"null" forKey:@"SSID"];
[infoDict setObject:tempDictionary[@"RATE"] ? tempDictionary[@"RATE"] : @"0" forKey:@"SPEED"];