8

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 :-)

THelper
  • 15,333
  • 6
  • 64
  • 104
WrightsCS
  • 50,551
  • 22
  • 134
  • 186
  • I know this doesn't answer the question, but check out: http://stackoverflow.com/questions/2018110/accessing-using-the-mobilewifi-framework Do you know of any user mode apps that have been able to enable or disable wifi on a non-jailbroken iphone? There is a way to simply flag your app as requiring wifi but that's about all I know of. – Nimrod Jan 13 '10 at 00:00
  • That doesnt enable/disable wifi, just returns certain info. – WrightsCS Jan 13 '10 at 00:38
  • 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 Jan 28 '11 at 22:06

2 Answers2

8

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];
}
WrightsCS
  • 50,551
  • 22
  • 134
  • 186
  • 2
    I tried [[objc_getClass("SBWiFiManager") sharedInstance] setWiFiEnabled:NO]; in a sample iOS 4.2.1 app but its doing nothing. Is it possible that the function call is not working because its from my app and its not a dylib loaded under SpringBoard? – Abhijeet Pathak Sep 06 '11 at 06:38
  • 2
    This will not work from an app and MUST be called from a .dylib. – WrightsCS Sep 06 '11 at 06:45
  • 1
    Okay thanks. I haven't developed .dylib till now. Can you please point me towards a link which explains how to develop dylib for iphone. Is this a normal dylib for springboard or something like mobilesubstrate toggle? – Abhijeet Pathak Sep 06 '11 at 06:49
  • 1
    You can scope out github.com .. there are plenty of open source tweaks there. – WrightsCS Sep 06 '11 at 06:50
  • 2
    To be clear, `SBWiFiManager` is a class that only exists in SpringBoard. To call it, one must be running inside SpringBoard as either a dynamic library or a framework. – rpetrich Sep 06 '11 at 18:25
  • Yes. Thank you. I am now trying to compile dylib (made with theos) but I am getting following error: "error: ‘objc_getClass’ was not declared in this scope" (along with many other errors). How to include objective c headers in theos? Also function 'HOOK' is not being recognized. – Abhijeet Pathak Sep 07 '11 at 05:28
  • I am still not able to use HOOK. – Abhijeet Pathak Sep 07 '11 at 05:40
  • If you are using logos try `%hook`. – WrightsCS Sep 07 '11 at 06:09
  • How can I use your kind of HOOK? – Abhijeet Pathak Sep 07 '11 at 06:27
  • 3
    Thanks!!! I got it working with theos using this tutorial :) http://brandontreb.com/beginning-jailbroken-ios-development-your-first-tweak/ – igbopie Jul 26 '12 at 15:19
0

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
  • 2,794
  • 1
  • 17
  • 10