Jump to content

My Delphi App using a REST Service quits unexpectedly on Big Sur

Recommended Posts

Since upgrading to Big Sur, if an attempt to connect to the REST service fails, the App quits unexpectedly. For example, this happens if the user does not have WiFi open and tries to connect, or if the user cannot access the server (i.e. if the server is temporarily unavailable).

On previous versions of MacOS, the exception was handled correctly inside the App. 

Is there something I need to add to plist or something? Or has anything network related been phased out? 

(The App is developed using Delphi 10.3.3 Community Edition with TRestRequest and executeasync; on Catalina and earlier the ACompletionHandlerWithError is called and the exception handled there).

I believe the error being thrown is Runtime Error 231.

(I am very new to Apple Development, so apologies if I have missed an obvious place to search for information on this!)
There are no issues on Android, iOS or Windows or previous MacOS; only Big Sur.  

Share this post

Link to post

Patch released: December Apple Platforms Patch for RAD Studio 10.4.1 1.0 from December 17, 2020:


Share this post

Link to post
8 hours ago, Lars Fosdal said:

He is on 10.3.3 Community edition.

my fault ... sorry!  :classic_blush:

Share this post

Link to post

A fix for 10.3.3 Community edition would be really highly appreciated!!!  

Could anyone explain a work-around to fix this specific issue?  I've tried using NetHTTPRequest to check the connection first, and I get the same problem.  

I'm going to have some unhappy students in March if I can't fix this. 😞 



Share this post

Link to post

Have you considered a educational license ?

Share this post

Link to post

I'm using the Community Edition to make non-commercial free apps which my students (not from Computer Science) also like to use, especially on MacOS.  I'm not teaching Delphi programming, so at the moment I don't think educational licenses match my situation.  But I don't get any income from programming.


I think the main issue is likely to be related to Delphi calling URLConnection rather than URLSession from Mac's API in versions prior to 10.4.   It seems that the App works fine unless there is an exception related to a connection problem (which can no longer handled).  


Other than a work-around involving a dialog asking "Are you really connected to the internet?" :classic_unsure:, I wonder whether I could try calling NSURLSession from my App first with very basic parameters (url + port) and then if the App got Error -1200 (SSL Error), I would know the connection from TRestRequest (with all the SSL parameters) would be highly likely to succeed.   It means an additional round-trip on Big Sur, but I think my users would prefer a slight pause to the app disappearing if they don't have WiFi open!  (I'm assuming that if the SSL error is raised, the connection has successfully found the machine is connected to the internet, managed to look up the IP address for the url, and made an initial connection - so the server is accessible).  


I can find links explaining how to use NSURLSession in C and Swift, but I find it all a bit baffling... (https://stackoverflow.com/questions/40016361/nsurlsession-request-and-response)


Could anyone point me to how I could make a few lines of Delphi Code to try NSURLSession with a URL and port with a short timeout, and then ideally calling a success procedure if the error is -1200 SSL Error, or a failure procedure if the error is anything else (-1009 internet offline or -1001 Time out, etc.).


(Sorry, this isn't intended to be a "please write me some code" tread; I'm just feeling stumped by depreciated networking protocols for MacOS in Community Edition of Delphi 10.3.3; I'd like to try calling NSURLSession directly, perhaps based on something like TMacHTTPClient.DoExecuteRequest from 10.3.3, but I don't know where to start for using the .wrap, .alloc, etc. for NSURLSession).


Or if there is any other 10.3.3 Delphi component that will try to open a url and port and not close the App if it fails on Big Sur, that would be great.


(Of course if 10.4.1 is released for the Community Edition soon, that might solve all my problems!)


Share this post

Link to post

Well, I have managed to sort out a work-around for my own situation.  It won’t make my App acceptable for the App Store (as it can’t handle network connection issues properly on Big Sur), but it means I can get things working pretty reliably.

My problem mainly seems to be that Delphi 10.3.3's TRestRequest can't handle network connection problems on Big Sur.  So to make sure the internet is available, it is possible to use Kastri’s straightforward TConnectivity.IsConnectedtoInternet (DW.Connectivity), and I by letting the user choose how the connection is made initially, I can try to maximize the availability of the server.  If they try to access a server that isn’t available, it will still close the App without warning, but I’ve worked on the defaults and it's the best I can do for now.  (Pre-Big Sur and on other platforms, it can automatically try another server as the network exceptions can be handled).

Through the process, I’ve learnt a bit about how to call Mac API, and some of the great things Kastri has to offer.  

If anyone does know how I can do a MacOS / iOS quick connection to see if a specific server is available (something quick and easy like the terminal’s “nc -G 2 -Z  myhost.address.com 443”), that would really help me until Delphi Community gets a new release.  Not being able to debug directly on a Big Sur machine, makes it rather tricky!

  • Like 1

Share this post

Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now