I have an app where usually all devices are shown at the start page , that are connected to a specific Wifi (Access Point). Since the new iOS Update, no device is shown and in the Log it shows "No route to host". If have found similar questions to this issue but no answer found.
(This code is from the previous developer and I'm pretty new to iOS/swift coding, so I'm sorry...)
The error shows up when trying to send the broadcast... see the code below.
open func sendBroadcast(_ data: Data) throws {
if responseSource == nil {
try createSocket()
}
guard let source = responseSource else { return }
let UDPSocket = Int32(source.handle)
let socketLength = socklen_t(address.sin_len)
try data.withUnsafeBytes { (broadcastMessage) in
let broadcastMessageLength = data.count
let sent = withUnsafeMutablePointer(to: &address) { pointer -> Int in
let memory = UnsafeRawPointer(pointer).bindMemory(to: sockaddr.self, capacity: 1)
return sendto(UDPSocket, broadcastMessage.baseAddress, broadcastMessageLength, 0, memory, socketLength)
}
guard sent > 0 else {
if let errorString = String(validatingUTF8: strerror(errno)) {
debugPrint("UDP connection failed to send data: \(errorString)")
}
closeConnection()
throw ConnectionError.sendingMessageFailed(code: errno)
}
if sent == broadcastMessageLength {
// Success
debugPrint("UDP connection sent \(broadcastMessageLength) bytes")
}
}
}
Any help is appreciated.
I found out you have to request the Multicast Networking Entitlement from Apple: https://developer.apple.com/contact/request/networking-multicast
Since iOS 14.5 you have to request to use UDP...
If they give you the permission to use it, just follow these steps explained here: https://developer.apple.com/forums/thread/663271
They usually answer after 1-2 days.