最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

ios - iPhone WiFi connection to HotSpot not connected to internet fails - Stack Overflow

programmeradmin2浏览0评论

I have written an App which extracts data, over WiFi, from an instrument that creates its own WiFi Hotspot. The instrument provides no internet connection. The iPad version of this App is connects fine as there is no Cellular connection. To get the iPhone version of the App to connect, I have to disable Cellular. Disabling "WiFi Assist" within Cellular settings was not enough to prevent iOS from trying to route a connection over the cellular network. Is there not a programmatic way to stop iOS from looking for a connection supporting the internet. Apple is rather vague on this topic.

The following code doesn't force a WiFi only connection unless Cellular is disabled.

    let host = NWEndpoint.Host( ipAddress )
    let port = NWEndpoint.Port( portNumber )
    let endpoint = NWEndpoint.hostPort(host: host, port: port!)
    let msgToUser = "Attempting connection host:\(ipAddress) port:\(UInt16(portNumber)!)"
    sessionDelegate!.feedback( with: msgToUser)
    
    // Force Wi-Fi-only connectivity
    let parameters = NWParameters.tcp
    // Attempt to explicitly set the Wi-Fi interface
    if let wifiInterface = NWPathMonitor().currentPath.availableInterfaces.first(where: { $0.type == .wifi }) {
        parameters.requiredInterface = wifiInterface
    } else {
        print("⚠️ No available Wi-Fi interface found")
    }
    parameters.requiredInterfaceType = .wifi
    
    connection = NWConnection(to: endpoint, using: parameters)
发布评论

评论列表(0)

  1. 暂无评论