Search code examples
iphonesdkwifitoggle

iPhone Wi-Fi Manager SDK


I'm attempting several methods trying to enable/disable Wi-Fi (toggle). Here are some things I am trying:

//Enable
WiFiManagerClientEnable(WiFiManagerClientCreate(kCFAllocatorDefault, 0));
//Disable
WiFiManagerClientDisable(WiFiManagerClientCreate(kCFAllocatorDefault, 0));

-and-

//Enable
WiFiManagerClientSetProperty(WiFiManagerClientCreate(kCFAllocatorDefault, 0), @"AllowEnable", kCFBooleanTrue);
//Disable
WiFiManagerClientSetProperty(WiFiManagerClientCreate(kCFAllocatorDefault, 0), @"AllowEnable", kCFBooleanFalse);

Each of those end up crashing the app, even though I have an exception function (@try{}). I've imported the MobileWiFi.framework and everything, just cant seem to get this to work. Are these the correct methods I need to call to be able to enable/disable Wi-Fi?

NOTE: NOT FOR APP STORE :-)


Solution

  • From Application

    notify_post("com.yourcompany.yourapp.yournotification");
    

    From Dylib

    #import <SpringBoard/SBWiFiManager.h>
    
    HOOK(SpringBoard, applicationDidFinishLaunching$, void, id app) {
        //Listen for events via DARWIN NOTIFICATION CENTER
        CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), NULL,
         &NotificationReceivedCallback, CFSTR("com.yourcompany.yourapp.yournotification"), NULL, 
          CFNotificationSuspensionBehaviorCoalesce);
    }
    
    //THIS IS WHERE THE MAGIC HAPPENS
    static void NotificationReceivedCallback(CFNotificationCenterRef center, 
                                                void *observer, CFStringRef name, 
                                                const void *object, CFDictionaryRef 
                                                userInfo) 
    { 
        [[objc_getClass("SBWiFiManager") sharedInstance] setWiFiEnabled:NO];
    }