MobileWiFi.framework: Difference between revisions

From iPhone Development Wiki
(More documentation!)
(Added WiFiKit)
Line 4: Line 4:
}}
}}


'''MobileWiFi''' is the framework that manages WiFi functionality on iOS. It powers [[WiFiPicker.servicebundle]], the Wi-Fi settings page and more. Its main purpose is to be a front-end to [[wifid]], which acquires its data directly from the kernel drivers. It replaces the obsolete '''Apple80211''' framework.
'''MobileWiFi''' is the framework that manages WiFi functionality on iOS. It powers [[WiFiPicker.servicebundle]], the Wi-Fi settings page and more. Its main purpose is to be a front-end to [[wifid]], which acquires its data directly from the kernel drivers. It replaces the obsolete '''Apple80211''' framework, but its methods are still available in IPConfiguration.bundle and bypasses wifid.
 
MobileWiFi is a C API but [[WiFiKit]] offers its functionality in a higher level ObjC API.


For examples on how to use this framework, see the [[#Example Code | Example Code]] section of this page.
For examples on how to use this framework, see the [[#Example Code | Example Code]] section of this page.

Revision as of 22:14, 7 May 2020

MobileWiFi.framework
Private Framework
Availabile 3.0 – present
Headers [headers.cynder.me]


MobileWiFi is the framework that manages WiFi functionality on iOS. It powers WiFiPicker.servicebundle, the Wi-Fi settings page and more. Its main purpose is to be a front-end to wifid, which acquires its data directly from the kernel drivers. It replaces the obsolete Apple80211 framework, but its methods are still available in IPConfiguration.bundle and bypasses wifid.

MobileWiFi is a C API but WiFiKit offers its functionality in a higher level ObjC API.

For examples on how to use this framework, see the Example Code section of this page.

  • Note: Your program needs the com.apple.wifi.manager-access entitlement to use any of the WiFiManager functions.

Example Code

This section includes example code that uses this framework. For more in-depth examples, see the following open-source projects:

Retrieving a list of known networks

#include <MobileWiFi.h>

WiFiManagerRef manager = WiFiManagerClientCreate(kCFAllocatorDefault, 0);

CFArrayRef networks = WiFiManagerClientCopyNetworks(manager);

NSLog(@"networks: %@", networks);

CFRelease(manager);
CFRelease(networks);

Getting the WiFi signal strength

#include <math.h>
#include <MobileWiFi.h>

WiFiManagerRef manager = WiFiManagerClientCreate(kCFAllocatorDefault, 0);
CFArrayRef devices = WiFiManagerClientCopyDevices(manager);

WiFiDeviceClientRef client = (WiFiDeviceClientRef)CFArrayGetValueAtIndex(devices, 0);
CFDictionaryRef data = (CFDictionaryRef)WiFiDeviceClientCopyProperty(client, CFSTR("RSSI"));
CFNumberRef scaled = (CFNumberRef)WiFiDeviceClientCopyProperty(client, kWiFiScaledRSSIKey);

CFNumberRef RSSI = (CFNumberRef)CFDictionaryGetValue(data, CFSTR("RSSI_CTL_AGR"));

int raw;
CFNumberGetValue(RSSI, kCFNumberIntType, &raw);

float strength;
CFNumberGetValue(scaled, kCFNumberFloatType, &strength);
CFRelease(scaled);

strength *= -1;

// Apple uses -3.0.
int bars = (int)ceilf(strength * -3.0f);
bars = MAX(1, MIN(bars, 3));


printf("WiFi signal strength: %d dBm\n\t Bars: %d\n", raw,  bars);

CFRelease(data);
CFRelease(scaled);
CFRelease(devices);
CFRelease(manager);

Scanning for nearby networks

#include <MobileWiFi.h>

static WiFiManagerRef _manager;
static void scan_callback(WiFiDeviceClientRef device, CFArrayRef results, CFErrorRef error, void *token);

int main(int argc, char **argv)
{
	_manager = WiFiManagerClientCreate(kCFAllocatorDefault, 0);

	CFArrayRef devices = WiFiManagerClientCopyDevices(_manager);
	if (!devices) {
		fprintf(stderr, "Couldn't get WiFi devices. Bailing.\n");
		exit(EXIT_FAILURE);
	}

	WiFiDeviceClientRef client = (WiFiDeviceClientRef)CFArrayGetValueAtIndex(devices, 0);

	WiFiManagerClientScheduleWithRunLoop(_manager, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);
	WiFiDeviceClientScanAsync(client, (CFDictionaryRef)[NSDictionary dictionary], scan_callback, 0);

	CFRelease(devices);

	CFRunLoopRun();

        return 0;
}

static void scan_callback(WiFiDeviceClientRef device, CFArrayRef results, CFErrorRef error, void *token)
{
	NSLog(@"Finished scanning! networks: %@", results);

	WiFiManagerClientUnscheduleFromRunLoop(_manager);
	CFRelease(_manager);

	CFRunLoopStop(CFRunLoopGetCurrent());
}

References