IPhone-SDK: activity indicator during startup?

I have a Default.png file in my project, so whenever my application runs the Default.png file, it loads there. Since my application retrieves data from the server at startup (application launch), I want to show an activity indicator, and the Default.png file is loading. Is it possible to activate both processes at a time, I mean to show Default.png and activate the activity indicator during startup? But I tried to enter an activity indicator code in "applicationDidFinishLaunching", but it does not show an activity indicator while displaying the Default.png file. But I'm sure that the action code that I have works fine on other screens. The problem is only during application launch.

Can anyone share their ideas?

thanks.

Clav /

+2
iphone
source share
4 answers

You cannot make animations in the Default.png image. You should replace it as soon as possible with view / controller (containing an activity indicator). Then, after showing this controller, load the data and possibly another controller (in the stream).

+4
source share

What I do in my application, the image with the Default.png image covering the screen is immediately loaded. then you can add a progress indicator at the top of the image while you are working on the background thread.

You should always avoid network activity in the applicationDidLaunch method, since this method has a timeout after which, if it does not return, Apple will kill your application. this is important because they say that the user is on the verge, and server shutdown takes 30 seconds - your application seems to have crashed into the user.

Performing network work in the background thread and returning applicationDidLaunch, you will not kill the Apple application, you can let the user use the application before new data arrives (if you want) and your application runs faster.

0
source share

You should always avoid network activity in the applicationDidLaunch method, since this method has a timeout after which, if it does not return, Apple will kill your application. this is important because they say that the user is on the verge, and server shutdown takes 30 seconds - your application seems to have crashed into the user.

So, you think that I should not put XMLPraser in 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!!!"); 
0
source share

How it works:
(Made on Xcode version 4.2.1)

So...

In AppDelegate.h add this:

 @property (nonatomic, strong) UIImageView *splashView; 

In AppDelegate.m add this:

At the top of the page 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]; } 

[UIView setAnimationDelay: 2.5] is responsible for how long the splashView will be ahead of the delay time you choose.

You can reposition the indicator by changing nubmers x / y to:
activityIndicator.center = CGPointMake (160, 360);

Finally, under the method:

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

Just add this:

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

And here you go :) Hope this helps.

Good programming ....

0
source share

All Articles