Hi, calls to URLSession for an IPv6 only domain (i.e. only an AAAA DNS record) within my app are failing even though the same domain name works in Safari. This is on a device with both an IPv4 and IPv6 connection when iCloud Private Relay is enabled and when it is not.
I'm trying to obtain the external IPv4 and IPv6 addresses of the user's device from my app using ipify.org's api4.ipify.org (IPv4), api64 (6 to 4) and api6 (IPv6) addresses. The issue I am having is within my app the api64 call always returns an IPv4 address and the api6 call just fails outright, resulting in a throw "A server with the specified hostname could not be found." api6.ipify.org only has an AAAA DNS record. But everything works right on the same device in Safari.
In Safari:
api4.ipify.org -> IPv4
api64.ipify.org -> IPv6 (since device has IPv6 connectivity)
api6.ipify.org -> IPv6
In my app though:
api4.ipify.org -> IPv4
api64.ipify.org -> IPv4 (but should return an IPv6 address, like for Safari)
api6.ipify.org -> IPv6 (fails...domain name not found)
Tried with cellular only connection (device has two public IPv6 addresses assigned) and from WiFi (device has both a private IPv4 and a private IPv6 address) and same results. Happening in both iOS 17.03 and 16.7.1.
I am having the exact same results when using other sites similar to ipify.org. 6to4 only returns an IPv4 address and AAAA record only domains fail, so not something specific to ipify.org.
Here's the code block that is failing within my app when api6.ipify.org is used and returns the wrong answer when api64 is used.
Thank you!
Task {
do {
let (data, _) = try await URLSession.shared.data(from: URL(string: "https://api<insert 4, 64 or 6>.ipify.org")!)
self.statusPublicIPv6 = String(data: data, encoding: .utf8) ?? ""
} catch {
print(error.localizedDescription)
}
}