Enable/Disable Wifi on non-jailbroken iOS device
Asked Answered
A

2

3

This I needed for my internal app. I want to toggle wifi on ios device. Any framework is available. I tried following code, but it provides me no help. This doesn't change my wifi settings.

{       
    Class BluetoothManager = objc_getClass("BluetoothManager");
    id btCont = [BluetoothManager sharedInstance];
    [self performSelector:@selector(toggle:) withObject:btCont afterDelay:0.1f] ;
}
- (void)toggle:(id)btCont
{
    BOOL currentState = [btCont enabled] ;
    [btCont setEnabled:!currentState] ;
    [btCont setPowered:!currentState] ;
    exit( EXIT_SUCCESS ) ;
}
Androsphinx answered 8/4, 2013 at 19:48 Comment(2)
There may (or may not) be ways to do this, using Apple internal interfaces, but they are not "approved" and would not pass App Store muster. You can't even test to see if you're in "airplane mode" or not.Edelweiss
Yes. I need only for internal purposeAndrosphinx
P
4

From Application

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

From Dylib

#import <objc/runtime.h>
#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];
}

Note:

if you enounter any error on using Hook method you can refer this link it demonstrates how to hook init method found in SpringBoard to show a alert message when starting up the phone.

Warning:

You can not use this for appstore apps since private api is used.

Reference

Attribtuion

Hope this helps.

Pleiades answered 23/3, 2014 at 11:43 Comment(0)
S
3

You're not going to be able to. iOS limits just how much third-party apps can interact with the underlying hardware. All applications written with the public SDK are sandboxed.

As 7KV7 says in their answer here:

They only have access to the properties and data which Apple deems feasible to use within that sandbox. I am afraid Wi-fi doesn't come in the list.

Subtenant answered 8/4, 2013 at 19:52 Comment(9)
I understand this is limitation to publish apps on App-Store. But this app is not meant for Appstore. This is my internal app. From where i want to toggle wifi settings of my phone. I am sure there is some hack to achieve this.Androsphinx
@user2259101, NO. You don't have permissions to access wifi settings. You will have to jailbreak.Honorine
@Androsphinx Nope. No way to do this.Subtenant
@ js1568 : can we achieve it using private frameworks on non-jailbroken device. I need to verify this on multiple devices.And it is not needed to have every device jailbreakAndrosphinx
@Androsphinx No, you won't be able to. Apple is pretty good at restricting what third-party apps can do.Subtenant
Can we change settings of non-jail broken device using scriptAndrosphinx
@Androsphinx No. There is absolutely no way to do this. Sorry :)Subtenant
then I am little curious how do people automate app testing where they need to test different scenarios with wifi setting on and also when wifi setting is offAndrosphinx
@Androsphinx Developers have a suite of instruments that come with Xcode that allow automated testing. Also, they just run thier tests with wifi on and with wifi off. Simple.Subtenant

© 2022 - 2024 — McMap. All rights reserved.