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.
这是我内部应用程序所需要的。我想在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 ) ;
}
2 个解决方案
#1
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.
你无法做到。 iOS限制了第三方应用程序可以与底层硬件交互的程度。使用公共SDK编写的所有应用程序都是沙箱。
As 7KV7 says in their answer here:
正如7KV7在他们的回答中所说:
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.
他们只能访问Apple认为可以在该沙箱中使用的属性和数据。我担心Wi-Fi不会出现在列表中。
#2
3
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.
如果您在使用Hook方法时遇到任何错误,可以参考此链接,它演示如何挂钩SpringBoard中的init方法,以便在启动手机时显示警告消息。
Warning:
You can not use this for appstore apps since private api is used.
由于使用了私有api,因此无法将此用于appstore应用。
Hope this helps.
希望这可以帮助。
#1
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.
你无法做到。 iOS限制了第三方应用程序可以与底层硬件交互的程度。使用公共SDK编写的所有应用程序都是沙箱。
As 7KV7 says in their answer here:
正如7KV7在他们的回答中所说:
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.
他们只能访问Apple认为可以在该沙箱中使用的属性和数据。我担心Wi-Fi不会出现在列表中。
#2
3
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.
如果您在使用Hook方法时遇到任何错误,可以参考此链接,它演示如何挂钩SpringBoard中的init方法,以便在启动手机时显示警告消息。
Warning:
You can not use this for appstore apps since private api is used.
由于使用了私有api,因此无法将此用于appstore应用。
Hope this helps.
希望这可以帮助。