iOS6.1: Problems while trying to access WiFi RSSI (MobileWiFi.framework)

流过昼夜 提交于 2019-12-09 13:39:49

问题


I'm trying to access the RSSI values of several APs around me using an iPod Touch 4G with iOS6.1 and Xcode 4.6.3 with a valid Provisioning Profile. I've read some discussions about this topic and the best way to do this seems to be using the private Framework MobileWifi. Since this project is for private usage only I'm ok with that.

According to this website I need a special entitlement in order to access the MobileWiFi functions. I've never worked with entitlements before, but according to some examples my .entitlement file looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>keychain-access-groups</key>
    <array>
        <string>$(AppIdentifierPrefix)com.apple.wifi.manager-access</string>
    </array>
</dict>
</plist>

I also did a jailbreak and installed AppSync in order to get rid of errors according to invalid entitlements. I am able to run the app on my iPod, but every time i want to check for networks or devices the app crashes. Here is my code so far:

WiFiManagerRef manager = WiFiManagerClientCreate(kCFAllocatorDefault, 0);
if (!manager)
    NSLog(@"ERROR: Couldn't create WiFiManagerClient!");

CFArrayRef devices = WiFiManagerClientCopyDevices(manager);
if (!devices)
    NSLog(@"ERROR: devices is NULL");

CFArrayRef networks = WiFiManagerClientCopyNetworks(manager);
if (!networks)
    NSLog(@"ERROR: networks is NULL");

NSLog(@"manager: %@", manager);
NSLog(@"%d devices: %@", (int)CFArrayGetCount(devices), devices);
NSLog(@"%d networks: %@",(int)CFArrayGetCount(networks), networks);

It seems that the WiFiManagerClientCopyDevices and WiFiManagerClientCopyNetworks methods return some bad values, if I set some checkpoint to check their addresses they're 0x00000000 after calling these methods and the app crashes due to EXC_BAD_ACCESS when returning their array count.

I've read that the MobileWifi functions won't work if I won't use the correct entitlements. Some others wrote that instead of a .entitlement file one should use a entitlement.xml file and use ldidto code sign the app and transfer it onto the device, but I don't like to do this manually since I prefer using Xcode's debugger and console while coding.

I spent a whole day trying to get rid of these problems but I didn't find any solutions, so I would be really glad if someone could help me out with this!


回答1:


To me it looks like your entitlements file is incorrect.

You have replaced your bundle id with the wifi.manager-access entitlement. You need to leave the keychain-access-group as it was and add the wifi.manager-access entitlement at the end of the file as new key/value pair.

Generate a new entitlement file in Xcode and add the following key/value pair.

    <key>com.apple.wifi.manager-access</key>
    <true/>

Your custom entitlements file should finally look something like that:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>keychain-access-groups</key>
    <array>
        <string>YOUR_APP_BUNDLE_ID</string>
    </array>
    <key>com.apple.wifi.manager-access</key>
    <true/>
</dict>
</plist>


来源:https://stackoverflow.com/questions/19303981/ios6-1-problems-while-trying-to-access-wifi-rssi-mobilewifi-framework

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!