iOS 13:使用新的 NEHotspotConfiguration.init(ssidPrefix: String) 似乎不起作用

iOS 13: Using the new NEHotspotConfiguration.init(ssidPrefix: String) does not seem to work

我目前是 运行 Xcode 11.0 和 iOS 13.1(测试版)。我正在试验 iOS 13 中新添加的功能,即能够连接到只有前缀已知的 Wifi 热点: Apple Docs

这非常适合无头配件的 Wifi 设置,因为您无需要求用户切换到 OS 设置即可连接到配件的 wifi。

但不幸的是我不能让它按预期工作。

我的代码(Swift 5):

if #available(iOS 13, *) {
        // The accessory's wifi name starts with "device-", followed by 3 digit number, e.g. "device-012"
        let configuration = NEHotspotConfiguration.init(ssidPrefix: "device-")
        configuration.joinOnce = true

        NEHotspotConfigurationManager.shared.apply(configuration) { (error) in
            if error != nil {
                if error?.localizedDescription == "already associated."
                {
                    print("Connected")
                }
                else {
                    print("No Connected")
                }
            }
            else {
                print("Connected")
            }
        }
    }

使用全名(例如"device-012"),有效:

let configuration = NEHotspotConfiguration.init(ssidPrefix: "device-012")

我错过了什么吗?前缀字符串可能需要一些通配符模式吗?

谢谢, 亨利

不设置 configuration.joinOnce = true 或将其设置为 false 即可。

错误报告已提交给 Apple。