问题
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 ) ;
}
回答1:
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.
回答2:
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.
来源:https://stackoverflow.com/questions/15887637/enable-disable-wifi-on-non-jailbroken-ios-device