views:

959

answers:

3

I'm attempting everal 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 :-)

A: 

You cannot disable WiFi on the phone. The user is responsible for this action through the Settings App, this capability is not available through the SDK.

-t

Tim
Well, I'm not writing the code for the App Store, my project is setup to use Private Frameworks.
AWright4911
Not sure why this was down-voted, it seemed an appropriate response to me.
Jayden
+1  A: 
//IN YOUR APP
notify_post("com.yourcompany.yourapp.yournotification");

//IN YOUR 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];
}
AWright4911
A: 

Hello, Am also trying something similar, can you please tell me more about the frameworks u have added and how to do this in xcode. Thanks in advance

PRN