iosswiftnetwork-programminglocalhost

NSURLErrorDomain Code=-1009 "The internet connection appears to be offline


I'm facing a problem sometimes while I try to request a local IP endpoint. In my case, I'm connected to a wifi hotspot and then I request this API endpoint. http://192.168.1.1:8080/appliance/info

The error log is provided below:

Connection 40: received failure notification
Connection 40: failed to connect 1:50, reason -1
Connection 40: encountered error(1:50)
Task <5419BE8A-533C-48A8-A5C6-3911C0D9481C>.<2> HTTP load failed, 0/0 bytes (error code: -1009 [1:50])
Task <5419BE8A-533C-48A8-A5C6-3911C0D9481C>.<2> finished with error [-1009] Error Domain=NSURLErrorDomain Code=-1009 "The internet connection appears to be offline." UserInfo={_kCFStreamErrorCodeKey=50, NSUnderlyingError=0x122825fe0 {Error Domain=kCFErrorDomainCFNetwork Code=-1009 "(null)" UserInfo={_NSURLErrorNWPathKey=unsatisfied (Local network prohibited), interface: en0[802.11], ipv4, uses wifi, _kCFStreamErrorCodeKey=50, _kCFStreamErrorDomainKey=1}}, _NSURLErrorFailingURLSessionTaskErrorKey=LocalDataTask <5419BE8A-533C-48A8-A5C6-3911C0D9481C>.<2>, _NSURLErrorRelatedURLSessionTaskErrorKey=(
    "LocalDataTask <5419BE8A-533C-48A8-A5C6-3911C0D9481C>.<2>"
), NSLocalizedDescription=The internet connection appears to be offline., NSErrorFailingURLStringKey=http://192.168.1.1:8080/appliance/info, NSErrorFailingURLKey=http://192.168.1.1:8080/appliance/info, _kCFStreamErrorDomainKey=1}
2024-04-30 13:44:27: 🔴 (95) Provider.didReceive() - GET:/appliance/info - URLSessionTask failed with error: The internet connection appears to be offline. - internalServerError - 500

I've checked that if I request this endpoint in my Safari or Chrome browser it provides me my expected data. It also works on my new demo iOS app. But, It always fails from my main application. I am sharing with you my info.plist file configuration for App Transport Security. Unfortunately, that Security configuration didn't solve my problem. The info.plist is provided below. Info Plist screenshot

I am also sharing the network info from my phone. Network info enter image description here Any kind of help or suggestions are appreciated.


Solution

  • This seems like an Apple bug.

    To those facing the same issue: This is a bug from Apple. I found out the reason behind this problem but no proper solution. When I request the Local Network Usage usage permission for the first time If I decline it I always get this 500 - Internal server error. But next time, I go to settings and enable the permission manually, It's still the same 500 - Internal server error. Even if I uninstalled the app, it kept happening.

    Solution: Restart the phone in this case. I've tested this behavior on iPhone 13, iPhone XS, and iPhone 15 pro and our testers also tested this behavior on other devices.

    Note: I am still looking for a proper solution that can be done instead of restarting the phone.