iOS 7 (non-jailbreak) Wi-Fi RSSI value

前端 未结 1 1251
-上瘾入骨i
-上瘾入骨i 2021-01-20 00:22

Is it possible to get Wi-Fi RSSI value on non-jailbroken iOS 7 device? I read about MobileWiFi.framework and Apple80211 functions and if I understand correct th

1条回答
  •  南方客
    南方客 (楼主)
    2021-01-20 00:35

    I can't find the original post from where this was taken but it worked for me on a jailed device running iOS 7.1 (doesn't work on iOS 8):

    #include 
    
    -(NSDictionary *)currentWiFiInfo
    {
       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 *error;
    
       if (libHandle == NULL && (error = dlerror()) != NULL)  {
          NSLog(@"%s", 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"];
    
       return infoDict;
    }
    

    0 讨论(0)
提交回复
热议问题