swift 4 中的代码是否可以关闭 wifi 或将 iPhone 切换到离线模式?

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

我想知道有什么方法可以打开或关闭iPhone wifi 或在swift 4 中的代码中将设备切换到离线模式 我知道苹果可能不允许应用程序可以做这样的事情在 App Store 中分发但这并不重要我只是想知道是否有任何代码可以做到这一点(就在 swift 4)

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

答案

  • 你不能。 Apple 不允许第 3 方应用程序那样更改全局系统设置。
  • 没有 API 可用于在应用程序中控制蜂窝数据、wi-fi、蓝牙,用户必须转到设置以启用或禁用蜂窝数据、wi-fi 和蓝牙。
  • 这在 iOS 中是不可能的,除非您越狱了您的设备。 Apple 不允许任何应用开发者访问 wifi/bluetooth。您只能检查 wifi/tooth 是否已连接。
  • 您不能使用 iOS 应用程序执行此操作。 Apple 不允许。
  • 在法律上是没有办法的。即使您以某种方式设法做到这一点,Apple 也会在提交到 AppStore 时拒绝您的应用程序。

更新

我不确定以下代码是否有效,尝试一次,最初添加 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