Stas
Stas

Reputation: 9935

Can I do something while splash is being showed?

Please tell me can I use a time while application is loading (while splash screen is being showed) to perform some background operations? (I need to call CLLocationManager and update current location) If I'm allowed to do it please tell me where to put a code.

Upvotes: 0

Views: 212

Answers (1)

Vladimir
Vladimir

Reputation: 7801

It is not possible to perform anything while real splash screen is shown. Your actions starts in

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 

method which is executed when splash screen removed. If you want to perform some time-cost operation before showing user interface, your only options is show manually "fake" splash screen during this time. It can be image or anything else e.g. activity indicator or animation. If you use same image that used for splash screen, user will see no difference, it will look like splash screen will remain some seconds longer for him, but you will already have your data loaded.

In this case your app delegate may be like this:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    self.viewController = [[ViewController alloc] 
    initWithNibName:@"FakeSplashViewController" bundle:nil];
    self.window.rootViewController = self.viewController;
    [self performSelectorInBackground: @selector(someLongOperation) withObject: nil];
    [self.window makeKeyAndVisible];
    return YES;
}

- (void) someLongOperation{
    //doing something
    //...
    [self performSelectorOnMainThread:@selector(atLastLoadGUI) withObject:nil waitUntilDone:NO];
}

- (void) atLastLoadGUI{
    // start GUI
}

Upvotes: 2

Related Questions