Callbacks

I,


I try to use Google Firebase API in my app.


Most of the API Method are based on callbacks.


I have to fetch some data as soon as possible when App launch ==> So, I try to make these call from AppDelegate.didFinishLaunchingWithOptions.


Problem : App exit from AppDelegate.didFinishLaunchingWithOptions before callbacks results and this leads to low level error (ssl error with 9802 or 9806 errors)


==> Is there a good parttern to manage such a situation ?


==> I tried a basic approach base on semaphore to force my App to wait for callback result but It doesn'ot work I think it's beacouse API call aremade from one thread/queue and callbacks returns on another.


Thanks in advance,


I hope it's almost clear... As you can see I 'm not familiar with GDC concepts.


David.

Replies

App exit from AppDelegate.didFinishLaunchingWithOptions before callbacks results and this leads to low level error (ssl error with 9802 or 9806 errors)

I presume you mean negative 9802 and 9806 here. If so, those are

errSSLFatalAlert
and
errSSLClosedAbort
, which are indeed low-level TLS errors.

I’m mystified why these would result from your app starting async work in

-application:didFinishLaunchingWithOptions:
. I can’t think of any way that these would be connected. Certainly that’s not the case when you use the built-in high-level networking APIs, like NSURLSession.

I tried a basic approach base on semaphore to force my App to wait for callback result …

That’s not going to work well even if you sort out the mechanics. You can’t block waiting for the network in

-application:didFinishLaunchingWithOptions:
because that blocks your app’s entire UI. Eventually you’ll get killed by the watchdog. QA1693 Synchronous Networking On The Main Thread covers this in depth.

Is there a good parttern to manage such a situation ?

This really depends on whether your app can interact with the user before these requests are complete. If it can, you should just return from

-application:didFinishLaunchingWithOptions:
and let the requests complete in the background. If it can’t, then your app should put up a ‘loading’ UI that prevents user interaction (except possibly cancellation) until the requests have complete.

I don’t think this has anything to do with the low-level TLS errors you’re seeing; you’ll need to investigate those separately. To do that I recommend you not run the requests from

-application:didFinishLaunchingWithOptions:
but instead add a temporary button to your UI to kick off the requests. One of two things will then happen:
  • If you still see the low-level TLS errors, you know that you TLS problem.

  • If not, there’s something very odd going on.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"