0

I have integrated branch.io(https://branch.io/) in my app for deep linking. Here the response that I am getting in the branch handler has a slight delay. Once I get the response I do some other processing and then decide whether to navigate to first screen or the second screen.

The problem is even before getting the branch response, the first screen is displayed. I want to delay the splash screen for a while (which is not good as most of the people say but I do not have any option probably). I referred to various links, How can I display a splash screen for longer on an iPhone? where they suggest to add a splash view. But this is not working. I donot know for what reason. I also used [NSThread sleepForTimeInterval:6.0]; But this blocks the main thread. I also used GCD which didn't help.

In didFinishLaunchingWithOptions, this is what I have coded,

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, NULL), ^{

        dispatch_async(dispatch_get_main_queue(), ^{
            //get branch response
        });

    });

But the first screen is appearing before getting the response from branch.io. Kindly help.... This is major problem in my app without which I cannot test anything.. Please help me... Let me know if I have not made myself clear..

Community
  • 1
  • 1
Medha
  • 39
  • 1
  • 6

2 Answers2

2

Why not creating screen between splash screen and main screen, that will load needed data and when it's done it will be redirected to main screen. It will say something like wait until data loads and may show some progress indicator. I think it's the best of possible solutions.

Volodymyr
  • 1,165
  • 5
  • 16
0

You can run webservice in main thread in didFinishLaunchingWithOptions. The splash screen will wailt until the service finished. After that you can choose with screen will be pushed to.

Remember handle the case the API is failed.

Proton
  • 1,335
  • 1
  • 10
  • 16
  • Alex from Branch.io here: this should work. As a side note, the API call is actually handled via our SDK, which is guaranteed to return a value in every situation (even when the network is out, or the API callback otherwise fails). – Alex Bauer Jun 28 '16 at 22:30
  • OK, understood ! Wait until the completion block of fetching web service, call `[self.window makeKeyAndVisible]` – Proton Jun 29 '16 at 03:19