Splash screen while receiving web service data

0

Hello!  I have a following problem: I need a splash screen that stays on screen while the app receives the data from the web service to popular a BD sqlite on the iPhone.  I tried using the Xcode image launch, but the image only stays on the screen for 2 seconds, and then the screen goes black.

Has anyone ever been through this? Thank you !!

    
asked by anonymous 19.07.2014 / 19:09

2 answers

2

At time of application:didFinishLaunchingWithOptions: in AppDelegate, your app is ready to display the root controller, defined via code in that method itself or in IB if you are using storyboard.

If you call the webservice synchronously, within application:didFinishLaunchingWithOptions: , your application will stay on the splash screen, but this is not a good practice, it will block the user interface.

Then, in your root controller, while waiting for the data to be returned from the service, do the following:

NO CODE:

#import "ViewController.h"

@interface ViewController ()
// crie uma propriedade para poder acessa-la no retorno dos dados do serviço.
@property (strong, nonatomic) UIView *splashScreenView;
@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];

    // Cria a splash view
    self.splashScreenView = [[UIView alloc] initWithFrame:self.view.bounds];
   // define o background
    self.splashScreenView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"splash-screen"]];
    // cria o spinner
    UIActivityIndicatorView *loading = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
    [loading startAnimating];
    // adiciona o spinner na splash view
    [self.splashScreenView addSubview:loading];
    // posiciona o spinner no centro da splash view.
    loading.center = self.splashScreenView.center;
    // adiciona a splash view na view do controller
    [self.view addSubview:self.splashScreenView];
}

- (void)meusDadosDoWebserviceRetornaAqui
{
    // quando receber seus dados, remova a splash view da view do controller.
    [self.splashScreenView removeFromSuperview];
}

Of course, you can do all this with some coolness, like an animation and such ... In addition to this View you can also do it in IB with a NIB file.

There it is with you!

And the result is this below:

    
24.07.2014 / 21:39
1

You can not control the splash to make it last longer on the screen.

I suggest you create a new viewcontroller that shows the splash screen image ( default.png ) in the application:didFinishLaunchingWithOptions: method of AppDelegate and if you want, put a loading message or a UIActivityIndicator to give feedback to the user that something is happening behind.

    
19.07.2014 / 20:52