在未越狱的iOS设备上启用/禁用Wifi [英] Enable/Disable Wifi on non-jailbroken iOS device
本文介绍了在未越狱的iOS设备上启用/禁用Wifi的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的内部应用程序所需要的.我想在ios设备上切换wifi.任何框架都可用. 我尝试了下面的代码,但它没有提供任何帮助.这不会更改我的wifi设置.
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 ) ;
}
推荐答案
来自应用程序
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方法以在启动手机时显示警报消息.
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.
由于使用了私有API,因此您不能将其用于Appstore应用程序.
You can not use this for appstore apps since private api is used.
希望这会有所帮助.
这篇关于在未越狱的iOS设备上启用/禁用Wifi的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文