Deprecated: trim(): Passing null to parameter #1 ($string) of type string is deprecated in /var/www/html/extensions/Variables/includes/ExtVariables.php on line 198

Deprecated: trim(): Passing null to parameter #1 ($string) of type string is deprecated in /var/www/html/extensions/Variables/includes/ExtVariables.php on line 198

Deprecated: trim(): Passing null to parameter #1 ($string) of type string is deprecated in /var/www/html/extensions/Variables/includes/ExtVariables.php on line 198
MobileWiFi.framework: Difference between revisions - iPhone Development Wiki

MobileWiFi.framework: Difference between revisions

From iPhone Development Wiki
No edit summary
No edit summary
Line 26: Line 26:
#include <MobileWiFi.h>
#include <MobileWiFi.h>


// We're not using the manager here but you need to create one for this code to work.
WiFiManagerRef manager = WiFiManagerClientCreate(kCFAllocatorDefault, 0);
WiFiManagerRef manager = WiFiManagerClientCreate();
CFArrayRef devices = WiFiManagerClientCopyDevices(_manager);
CFArrayRef devices = WiFiManagerClientCopyDevices();


WiFiDeviceClientRef client = (WiFiDeviceClientRef)CFArrayGetValueAtIndex(devices, 0);
WiFiDeviceClientRef client = (WiFiDeviceClientRef)CFArrayGetValueAtIndex(devices, 0);
Line 41: Line 40:
strength = ceilf(strength);
strength = ceilf(strength);


// Convert to a negative number.
// Convert to a negative number (RSSI is negative).
strength = strength * -1;
strength = strength * -1;


Line 76: Line 75:
{
{
     NSLog(@"Networks: %@", results);
     NSLog(@"Networks: %@", results);
     WiFiManagerClientUnscheduleFromRunLoop(_manager);
     WiFiManagerClientUnscheduleFromRunLoop(_manager);
     CFRelease(_manager);
     CFRelease(_manager);

Revision as of 03:20, 1 June 2013

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


MobileWiFi is the framework that manages WiFi functionality on iOS. It replaces the obsolete Apple80211 framework.

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

Retrieving a list of known networks

#include <MobileWiFi.h>

WiFiManagerRef manager = WiFiManagerClientCreate();

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);
CFNumberRef RSSI = (CFNumberRef)WiFiDeviceClientCopyProperty(client, kWiFiScaledRSSIKey);

float strength;
CFNumberGetValue(RSSI, kCFNumberFloatType, &strength);

strength = strength * 100;

// Round to the nearest integer.
strength = ceilf(strength);

// Convert to a negative number (RSSI is negative).
strength = strength * -1;

NSLog(@"WiFi signal strength: %f dBm", strength);

CFRelease(RSSI);
CFRelease(devices);
CFRelease(manager);

Scanning for nearby networks

#include <MobileWiFi.h>
 
WiFiManagerRef _manager;
WiFiDeviceClientRef _client;

int main()
{
    _manager = WiFiManagerClientCreate(kCFAllocatorDefault, 0);

    CFArrayRef devices = WiFiManagerClientCopyDevices(_manager);
    _client = (WiFiDeviceClientRef)CFArrayGetValueAtIndex(devices, 0);

    WiFiManagerClientScheduleWithRunLoop(_manager, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);
    WiFiDeviceClientScanAsync(_client, (CFDictionaryRef)[NSDictionary dictionary], scanCallback, 0);

    CFRelease(devices);
}

void scanCallback(WiFiDeviceClientRef device, CFArrayRef results, WiFiErrorRef error, void *token)
{
    NSLog(@"Networks: %@", results);

    WiFiManagerClientUnscheduleFromRunLoop(_manager);
    CFRelease(_manager);
}

References