4

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)

Saeed Rahmatolahi
  • 1,183
  • 1
  • 18
  • 46

1 Answers1

7

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
Anbu.Karthik
  • 77,564
  • 21
  • 153
  • 132
  • ok I know that the apple will reject the app I just want to know is there any codes or not ? – Saeed Rahmatolahi Feb 05 '18 at 05:16
  • @SaeedRahmatolahi - not sure the reference link will work or not, if it is works, then use the update answer – Anbu.Karthik Feb 05 '18 at 05:26
  • I received this error in the first line of your codes (Use of undeclared type 'SBWiFiManager') – Saeed Rahmatolahi Feb 05 '18 at 05:42
  • are you integrated the SBWiFiManager.h in your project from https://github.com/pigigaldi/iOS-6-Headers/blob/master/SpringBoard/SBWiFiManager.h – Anbu.Karthik Feb 05 '18 at 05:46
  • so I have to make a class and then put that code there and then using your codes here in my codes right ? – Saeed Rahmatolahi Feb 05 '18 at 05:49
  • @SaeedRahmatolahi - the class is already available in that link , just drag and drop in the https://github.com/pigigaldi/iOS-6-Headers/blob/master/SpringBoard/SBWiFiManager.h in your project and it will create the bridging header, then use the above code it will work – Anbu.Karthik Feb 05 '18 at 05:50
  • ok thanks I will do it and if there was a problem I will comment here – Saeed Rahmatolahi Feb 05 '18 at 06:01
  • @SaeedRahmatolahi - sure – Anbu.Karthik Feb 05 '18 at 06:02
  • Hello @Anbu.Karthik does Mobile Device Management accommodate the OPs point? I am looking for something similar in iOS but it seems there are a lot of restrictions with controlling wifi and mobile data. Thanks – Spurdow Mar 27 '21 at 09:11