WiFiKit.framework

From iPhone Development Wiki
Jump to: navigation, search

WiFiKit is a private framework that provides a high-level ObjC API to MobileWiFi.framework. Its functionality used to be in AirPortSettings.bundle but it has now been factored out to this new framework and AirPortSettings now contains simply one class APNetworksController that uses WFNetworkListController from this framework.

It requires the com.apple.wifi.manager-access entitlement.

#import <WiFiKit/WiFiKit.h>

@interface AppDelegate () <WFScanManagerDelegate>

@property (strong, nonatomic) WFScanManager *scanManager;

@end

@implementation AppDelegate

- (WFScanManager *)scanManager{
    if(!_scanManager){
        Class WFClientClass = NSClassFromString(@"WFClient"); // Because I can't yet link the framework.
        WFClient *client = [WFClientClass.alloc init];
        Class WFScanManagerClass = NSClassFromString(@"WFScanManager");
        _scanManager = [WFScanManagerClass.alloc initWithClient:client scanInterval:6 delegate:self]; // minimum 6
    }
    return _scanManager;
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    [self.scanManager start];
    return YES;
}

// called first for 2.4GHz then second for 5GHz
-(void)scanManager:(WFScanManager *)scanManager updatedPartialResults:(NSSet<WFNetworkScanRecord *> *)partialResults{
    NSLog(@"%@", NSStringFromSelector(_cmd));
}

// called immediately after 5GHz partial
- (void)scanManagerScanningDidFinish:(WFScanManager *)scanManager withResults:(NSSet<WFNetworkScanRecord *> *)results error:(NSError *)error{
    NSLog(@"%@", NSStringFromSelector(_cmd));
}

References