Domanda

I have an app where the first screen user sees has data that is fetched from the server. The app also has a splash screen that shows up when the app is being loaded.

Problem Depending on the users connection time it might take a few seconds for the data to load. In this scenario, the splash screen comes up for few seconds and then I just see a blank (black) screen for another few seconds and then I see the first screen. I suspect the blank screen comes up for the time it takes to fetch data from the server. I looking for ways to solve this issue

Question

  • Can the length of time the splash screen shows up be configured? For example, maybe the splash screen can stay up till the data is fetched?
  • Can some sort of spinner be showed instead of a black blank screen while data is being loaded?

Update

This is how I'm loading the data

  def self.fetch(client, &block)
    client.shared.headers["username"] = App::Persistence["username"]
    client.shared.headers["token"] = App::Persistence["sessionId"]
    client.shared.get('categories') do |result|
      if result.success?
        ary = result.object
        block.call(ary)
      end
    end
  end

and to use it

  def application(application, didFinishLaunchingWithOptions:launchOptions)
      @window = UIWindow.alloc.initWithFrame(UIScreen.mainScreen.bounds)
      Color.fetch(AFMotion::Client) do |data|
        main_controller = ColorController.alloc.initWithData(data)
        @window.rootViewController = UINavigationController.alloc.initWithRootViewController(main_controller)
        @window.rootViewController.navigationBar.barTintColor = '#DF533B'.to_color
        @window.rootViewController.navigationBar.translucent = true
        @window.rootViewController.navigationBar.tintColor = UIColor.whiteColor
        @window.rootViewController.navigationBar.setTitleTextAttributes({
            UITextAttributeTextColor => UIColor.whiteColor
        })
      end
      @window.makeKeyAndVisible

      @window.tintColor = '#DF533B'.to_color
    end
È stato utile?

Soluzione

Yes it can, but it should not be done. The "splash" screen is shown when you app is being loaded in memory. You can delay the remove all of this screen bij not return directly form the application:didFinishLaunchingWithOptions: method. But doing so might get your app killed by the os because it is take to long to load.

You best option to place a view in the UIWindow that show that your app is downloading data. This way your user see that your app is doing something. If it is possible to show some kind of progress here that would even be better.

You could even do it in the view controller where you perform the network call, just push a loading view onto the view just before you start the netwerk call. Once it is finished remove the view. This will work only if the network call is not blocking any UI updates.

Altri suggerimenti

The "splash screen" or what you set to Default.png cannot be set to be longer. It is only shown until your app has launched. You are also right in thinking that your app is staying on a black screen because the fetching might take long.

To solve this problem you can do a couple things.

  1. Move data fetching to an other thread than the mainThread so that the UI is not locked and then refresh your view once the data has finished downloading. while that is happening you can show a spinner or whatever you want.

[self showLoadingView];

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{

    [self doDataFetch];

    dispatch_async(dispatch_get_main_queue(), ^{

        [self hideLoadingView];
        [self reloadView];
    });
});

  1. Show a different controller at launch in the application:didFinishLaunchingWithOptions and then download your data in the background and when that is done show the view controller that requires the data.

The takeaway is that you should not do the data fetch on the mainThread. DO IT IN THE BACKGROUND. This will prevent the UI from locking and the app taking long to load.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top