在非越狱的iOS设备上启用/禁用Wifi

这我需要我的内部应用程序。 我想在iOS设备上切换wifi。 任何框架都可用。 我尝试了下面的代码,但它没有提供任何帮助。 这不会改变我的WiFi设置。

{ 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 ) ; } 

你不能这样做。 iOS限制了第三方应用程序能够与底层硬件交互的程度。 所有使用公共SDK编写的应用程序都是沙盒的。

正如7KV7在这里回答的那样 :

他们只能访问苹果认为可以在该沙箱内使用的属性和数据。 恐怕Wi-Fi不在列表中。

从应用程序

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

从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]; } 

注意:

如果您在使用Hook方法时遇到任何错误,您可以参考这个链接,它演示了如何在启动电话时,钩住SpringBoard中的init方法以显示警告消息。

警告:

由于使用了私有api,所以不能将其用于appstore应用程序。

参考

Attribtuion

希望这可以帮助。