IPv6 only domain not working for URLSession

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)
   }
}

Also getting the following errors when URLSession is called, the device is online though and as stated before, everything works in Safari and URLSession for api4.ipify.org is working and api64 doesn't throw an error but returns the wrong result.

nw_endpoint_copy_association_with_evaluator nw_context_caches_are_shared(context (<nw_context com.apple.CFNetwork.NSURLSession.{9A54EA8A-B2C0-4DC0-A798-D53DA91606CA}{(null)}{Y}{2}{0x0} (private)>), endpoint->context (<nw_context Default Network Context (private)>)) is false

quic_protector_key_update unsupported TLS ciphersuite: 0

Connection 4: received failure notification

Connection 4: failed to connect 1:50, reason 18,446,744,073,709,551,615

Connection 4: encountered error(1:50)

Task <E1DEBE76-8C44-4C9E-A183-70EBCC272F62>.<1> HTTP load failed, 0/0 bytes (error code: 18,446,744,073,709,550,607 [1:50]) Task <E1DEBE76-8C44-4C9E-A183-70EBCC272F62>.<1> finished with error [18,446,744,073,709,550,607] Error Domain=NSURLErrorDomain Code=-1009 "The Internet connection appears to be offline." UserInfo={_kCFStreamErrorCodeKey=50, NSUnderlyingError=0x2834909c0 {Error Domain=kCFErrorDomainCFNetwork Code=-1009 "(null)" UserInfo={_NSURLErrorNWPathKey=satisfied (Path is satisfied), interface: en0[802.11], ipv4, dns, _kCFStreamErrorCodeKey=50, _kCFStreamErrorDomainKey=1}}, _NSURLErrorFailingURLSessionTaskErrorKey=LocalDataTask <E1DEBE76-8C44-4C9E-A183-70EBCC272F62>.<1>, _NSURLErrorRelatedURLSessionTaskErrorKey=( "LocalDataTask <E1DEBE76-8C44-4C9E-A183-70EBCC272F62>.<1>" ), NSLocalizedDescription=The Internet connection appears to be offline., NSErrorFailingURLStringKey=https://api6.ipify.org/, NSErrorFailingURLKey=https://api6.ipify.org/, _kCFStreamErrorDomainKey=1}

Do you have iCloud Private Relay enabled?

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

IPv6 only domain not working for URLSession
 
 
Q