Код: Выделить всё
// Setting up the connection:
let tcpOptions = NWProtocolTCP.Options()
let parameters = NWParameters(tls: .init(), tcp: tcpOptions)
parameters.requiredInterfaceType = .cellular
port = port ?? NWEndpoint.Port(443)
// ...
NWConnection(to: .hostPort(host: NWEndpoint.Host(host),port: port), using: parameters)
//...
func receive(withConnection connection: NWConnection, completion: @escaping dataCompletion) {
connection.receive(minimumIncompleteLength: 1, maximumLength: Int.max) { [self] data, contentContext, isComplete, error in
if let data = data {
receivedData.append(data)
print(contentContext)
if isComplete || error != nil || connection.state != .ready {
cancelConnection(connection)
} else {
processor?.receive(withConnection: connection, completion: completion)
}
} else {
cancelConnection(connection)
}
}
}
Я' Я думал добавить тайм-аут, но это кажется хакерским. Есть ли лучшее решение?
Подробнее здесь: https://stackoverflow.com/questions/786 ... comes-true
Мобильная версия