iOS 16 introduced "Internationalized Domain Name" support for URLComponent
. As a result, URLComponent
does not accept IPv6 address as host in iOS 16. Is this expected behaviour or a bug, and what would be the best workaround in this case?
// IPv4 URL
var ipv4URLComponents = URLComponents()
ipv4URLComponents.scheme = "https"
ipv4URLComponents.host = "66.94.29.13"
if let url = ipv4URLComponents.url {
print("IPv4 URL:", url)
}
// IPv6 URL
var ipv6URLComponents = URLComponents()
ipv6URLComponents.scheme = "https"
ipv6URLComponents.host = "2001:0000:3238:dfe1:0063:0000:0000:fefb"
if let url = ipv6URLComponents.url {
print("IPv6 URL:", url)
}
Output on iOS 15.5 device:
IPv4 URL: https://66.94.29.13
IPv6 URL: https://2001%3A0000%3A3238%3Adfe1%3A0063%3A0000%3A0000%3Afefb
Output on iOS 16 device:
IPv4 URL: https://66.94.29.13
IPv6 URL: https:
Related thread: https://developer.apple.com/forums/thread/709284