2

I am having a Default.png file in my project, so that whenever my app launches Default.png file loads there. As my app is retrieving data from server at startup(app launch), i want to show activity indicator as well while Default.png file is loading. Is it possible to activate both the process at a time, i mean showing Default.png and enable activity indicator at a time during startup? But i tried putting Activity Indicator code in 'applicationDidFinishLaunching' but it doesn't show activity indicator at the time of showing Default.png file. But i am sure that Activity code what i have, is working fine on other screens. Problem is only during app launch.

Can someone share your ideas please?

thanks.

Clave/

  • Haven't you already asked this question? http://stackoverflow.com/questions/1404463/iphone-sdk-avoid-blank-screen-while-launching-my-application – Brad Larson Sep 16 '09 at 22:44

4 Answers4

4

You can't do any animation in the Default.png image. You should replace it as soon as possible with a view/controller (containing the activity indicator). Than after showing that controller, load your data and possibly an other controller (in a thread).

Pieter Jongsma
  • 3,365
  • 3
  • 27
  • 30
0

What i do in my app is immediately load an imageview with the Default.png image covering the screen. then you can add a progress indicator on top of the imageview while you do your server work on a background thread.

You should always avoid net activity in the applicationDidLaunch method as this method has a timeout after which, if it does not return, Apple will kill your app. this is important because say the user is on edge and the server trip takes 30 seconds - your app will appear to have crashed to the user.

By doing the net work in a background thread and returning applicationDidLaunch, you will keep apple from killing your app, you will be able to let the user use the app before the new data comes in (if you want) and your app will appear to launch faster.

coneybeare
  • 33,113
  • 21
  • 131
  • 183
0

You should always avoid net activity in the applicationDidLaunch method as this method has a timeout after which, if it does not return, Apple will kill your app. this is important because say the user is on edge and the server trip takes 30 seconds - your app will appear to have crashed to the user.

So you think that I should not put XMLPraser on the applicationDidLaunch?

NSURL *url = [[NSURL alloc] initWithString:@"http://sites.google.com/site/iphonesdktutorials/xml/Books.xml"];
NSXMLParser *xmlParser = [[NSXMLParser alloc] initWithContentsOfURL:url];

//Initialize the delegate.
XMLParser *parser = [[XMLParser alloc] initXMLParser];

//Set delegate
[xmlParser setDelegate:parser];

//Start parsing the XML file.
BOOL success = [xmlParser parse];

if(success)
    NSLog(@"No Errors");
else
    NSLog(@"Error Error Error!!!");
Leo
  • 37,640
  • 8
  • 75
  • 100
0

That's how it works:
(Made on Xcode version 4.2.1)

So...

In the AppDelegate.h add this:

@property (nonatomic, strong) UIImageView *splashView;

In the AppDelegate.m add this:

On the top of the page of cours @synthesize splashView;
And then:

- (void) splashFade
{
    splashView = [[UIImageView alloc] initWithFrame:CGRectMake(0,0, 320, 480)];
    splashView.image = [UIImage imageNamed:@"Default.png"];
    [_window addSubview:splashView];
    [_window bringSubviewToFront:splashView];
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:2.0];
    [UIView setAnimationDelay:2.5];
    [UIView setAnimationTransition:UIViewAnimationTransitionNone forView:_window cache:YES];
    [UIView setAnimationDelegate:self]; 
    [UIView setAnimationDidStopSelector:@selector(startupAnimationDone:finished:context:)];
    splashView.alpha = 0.0;
    [UIView commitAnimations];

    //Create and add the Activity Indicator to splashView
    UIActivityIndicatorView *activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
    activityIndicator.alpha = 1.0;
    activityIndicator.center = CGPointMake(160, 360);
    activityIndicator.hidesWhenStopped = NO;
    [splashView addSubview:activityIndicator];
    [activityIndicator startAnimating];
}

- (void)startupAnimationDone:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context
{
    [splashView removeFromSuperview];
}

The [UIView setAnimationDelay:2.5] is responsible for how long the splashView will be in front by the delay time you choose.

You can change the position of the indicator by changing the nubmers of x/y in:
activityIndicator.center = CGPointMake(160, 360);

At last, under the methode:

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

Just add this:

[self performSelector:@selector(splashFade) withObject:nil];

And there you go :)
Hope it helped.

Have a nice programming....

Maor Zohar
  • 592
  • 5
  • 17