URLConnection -1009 errors for Local connections

I’m having a very reproducible problem with URLConnection errors that seems very similar to this topic from 2 years ago.

It still occurs in both debug and built apps on Tahoe 26.6.2 using Xojo 26.2.1

The general symptom is that URLConnection Error -1009 event fires the first time the Xojo app tries to connect to a device on the LOCAL network. This would be when a typical app would post a dialog asking the user whether it’s OK to allow access to LOCAL devices. With Xojo that dialog almost never appears but the app immediately throws an exception that’s caught by the error event.

I’ve done extensive testing and it occurs in both debug and built apps. Retrying the URLconnection will generally work OK, UNTIL THE APP IS RECOMPILED. And then it fails in the same way.

Other URLConnections to remote servers work OK, either before or after attempting a local connection. But the first LOCAL connection attempt per newly compiled app always fails, even after a successful connection to a remote network.

I have added the NSAllowsLocalNetworking, NSAllowsArbitraryLoads and NSLocalNetworkUsageDescription keys to my plist file with no change in behavior.

It seems very related to the way Xojo is/isn’t handling the Allow Local Device access dialog.

Is anyone else having this issue? Comments and suggestions very welcome.

Cheers, Joe

Do you have the same issue if the app is Notarized?

The codesigned version has this problem, but I haven’t tried Notarizinng it.

I’ve only recently started codesigning (using Xojo) so I may not be doing that correctly. But I followed the process in your blog posts and do get this verification.

/Users/joe/Desktop/Runtime Insights.app: valid on disk

/Users/joe/Desktop/Runtime Insights.app: satisfies its Designated Requirement

Javier thanks for the suggestion. I Notarized my app and both the debug and built apps seem much better.

I believe there is still an underlying bug in that URLConnection doesn’t smoothly handle the suspend and retry required as Apple shows the Local Network access approval alert dialog. Xojo immediately throws an exception which can’t be handled properly at the Xojo level because we don’t know if the user approved local network accesses or not.

I will continue gathering info and may file a bug report/feature request for URLConnection to handle this more seamlessly.

Apple has a great TechNote on TN3179: Understanding local network privacy

One very relevant paragraph: “If the system presents a local network alert in response to one of your local network operations, it may deny the operation immediately, before the user has responded to the alert. To handle this smoothly, use an API that supports waiting for connectivity, like Network framework or URLSession with waitsForConnectivity enabled. If you can’t use one of these preferred APIs, add appropriate retry logic.”