is it possible to turn off wifi or switch iPhone to offline mode in codes in swift 4?

喜欢而已 提交于 2019-12-10 12:26:42

问题


I want to know is there any way to turn on or off the iPhone wifi or switch the device to offline mode in codes in swift 4 or not I know that apple may not allow the app can do such things to be distributed in App Store But it's Not important I just want to know is there any codes to do that or not (Just in swift 4)


回答1:


5 Solutions Collect From Internet About “How to turn off internet connection, bluetooth and WIFI programmatically?”

Ans

  • You can’t. Apple does not allow 3rd party apps to change global system settings like that.
  • There is no API available to control cellular data,wi-fi,bluetooth within in an app , User have to go to settings to enable or disable cellular data,wi-fi and bluetooth.
  • This is not possible in iOS unless you jailbroke your device. Apple is not allowing any apps developer to access wifi/bluetooth. You can only check wifi/tooth is connected or not.
  • You can’t do that using the iOS application. Apple not allowing it.
  • Legally there is no way to do it. Even somehow if you are manage to do it, Apple will reject your app while submitting to AppStore.

update

I am not sure the following code will work or not, try once, initially add the header file to your project folder and create the bridging header to your code ,then use the below code where you need , for ref purpose I taken the answer from here

var tempSBWifiManager: SBWiFiManager = objc_getClass("SBWiFiManager")
 // Steal a class from SpringBoard
 tempSBWifiManager.sharedInstance().isWiFiEnabled = false


来源:https://stackoverflow.com/questions/48616053/is-it-possible-to-turn-off-wifi-or-switch-iphone-to-offline-mode-in-codes-in-swi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!