xcode 以编程方式自动连接到 WiFi iOS

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/35613344/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 08:34:52  来源:igfitidea点击:

Programmatically auto-connect to WiFi iOS

iosxcodeswiftwifi

提问by Schavcovsky

I'm creating an app on Swift, and I need to know, if there's any way I can programatically auto connect an iPhone to a WiFi giving as paremeters the SSID and the Password from that WiFi Network.

我正在 Swift 上创建一个应用程序,我需要知道,是否有任何方法可以以编程方式将 iPhone 自动连接到 WiFi,并提供该 WiFi 网络的 SSID 和密码作为参数。

Thanks in advance.

提前致谢。

回答by Mayur Rathod

Below code will work on Xcode 9 and iOS 11

下面的代码适用于 Xcode 9 和 iOS 11

let WiFiConfig = NEHotspotConfiguration(ssid: "Mayur1",
                                                  passphrase: "123456789",
                                                  isWEP: false)

    WiFiConfig.joinOnce = false
    NEHotspotConfigurationManager.shared.apply(WiFiConfig) { error in
        // Handle error or success
        print(error?.localizedDescription)

回答by 0xa6a

Quotation from Apple Developer Documentation:

来自Apple 开发者文档的引用:

The NEHotspotHelper interface allows an app to participate in the process of joining Wi-Fi/hotspot networks. Such an app is referred to as a Hotspot Helper. A Hotspot Helper receives commands to be processed in the background that allow it to participate in the Hotspot Network state machine.

NEHotspotHelper 接口允许应用程序参与加入 Wi-Fi/热点网络的过程。这样的应用程序被称为热点助手。Hotspot Helper 接收要在后台处理的命令,允许它参与 Hotspot Network 状态机。

回答by brimstone

Not possible unfortunately! Too many issues that Apple would be not okay with. If you're working with a jailbroken device it may be possible (if it's not going on the app store, either)

不幸的是不可能!太多的问题是苹果公司无法解决的。如果您使用的是越狱设备,则有可能(如果它也没有在应用商店上架)

Here's a question similar to yours you might want to look at

这是一个与您类似的问题,您可能想看看