admin管理员组文章数量:1353228
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)
本文标签: iosiPhone WiFi connection to HotSpot not connected to internet failsStack Overflow
版权声明:本文标题:ios - iPhone WiFi connection to HotSpot not connected to internet fails - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743928306a2563373.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论