Следующий код не заставляет подключение только к Wi -Fi, если не отключено ячейка. < /P>
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("
}
parameters.requiredInterfaceType = .wifi
connection = NWConnection(to: endpoint, using: parameters)
Подробнее здесь: https://stackoverflow.com/questions/795 ... rnet-fails
Мобильная версия