Hi guys. I have a bit of a problem. Since iOS 4, my app thinks that it isn't loading, so it stops running because of Apple's wait timer function. It's actually loading the database for first time user's and any updates. How can I add in a loading screen before the app loads? I tried just a splash screen but it's no good.
here is the code that executes to check if the database needs to be loaded. The loading scree needs to be loaded if this check is true and show the activity indicator as long as the data is loading.
Hi guys. I have a bit of a problem. Since iOS 4, my app thinks that it isn't loading, so it stops running because of Apple's wait timer function. It's actually loading the database for first time user's and any updates. How can I add in a loading screen before the app loads? I tried just a splash screen but it's no good.
here is the code that executes to check if the database needs to be loaded. The loading scree needs to be loaded if this check is true and show the activity indicator as long as the data is loading.
In my app I have just got a default.png (image with a little graphic and text showing loading,please wait...) and it seems to be working OK.
Or you can use
UIActivityIndicatorView *spinner;
spinner = [[UIActivityIndicatorView alloc]
initWithActivityIndicatorStyle:UIActivityIndicator ViewStyleWhiteLarge];
[spinner setCenter:CGPointMake(160.0, 230.0)]; // I do this because I'm in landscape mode
[self.view addSubview:spinner];
//show an indicator we stop animatin on connectioFinishLoading
[spinner startAnimating];
In my app I have just got a default.png (image with a little graphic and text showing loading,please wait...) and it seems to be working OK.
Or you can use
UIActivityIndicatorView *spinner;
spinner = [[UIActivityIndicatorView alloc]
initWithActivityIndicatorStyle:UIActivityIndicator ViewStyleWhiteLarge];
[spinner setCenter:CGPointMake(160.0, 230.0)]; // I do this because I'm in landscape mode
[self.view addSubview:spinner];
//show an indicator we stop animatin on connectioFinishLoading
[spinner startAnimating];
[spinner stopAnimating];
maybe I am not sure!!
Looks like that may work. But i'm getting a failure after analyzing "Request for 'view' in something not a structure or union". Thoughts?
Hi guys. I have a bit of a problem. Since iOS 4, my app thinks that it isn't loading, so it stops running because of Apple's wait timer function. It's actually loading the database for first time user's and any updates. How can I add in a loading screen before the app loads? I tried just a splash screen but it's no good.
here is the code that executes to check if the database needs to be loaded. The loading scree needs to be loaded if this check is true and show the activity indicator as long as the data is loading.
Apple doesn't allow your didFinishLaunching/didFinishLaunchingWithOptions method to take more than a couple of seconds to complete or the system terminates your app as not responding.
The trick is to do the minimum of setup in didFinishLaunchingWithOptions, and then trigger the time-consuming action after you've returned to the main event loop. Ideally, do you time consuming work asynchronously so the user can start using the app.
The simplest way to release control is to use the method performSelector:withObject:afterDelay:
Something like this:
Code:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Add the view controller's view to the window and display.
self.navController = [[UINavigationController alloc] initWithRootViewController:viewController];
navController.toolbar.barStyle = UIBarStyleBlackOpaque;
[window addSubview:navController.view];
[window makeKeyAndVisible];
//This call returns immediately, then waits until the next time
//through the event loop to invoke the method.
[self performSelector: finishLaunching withObject: nil afterDelay: 0];
return YES;
}
- (void) finishLaunching;
{
if ([[Database shared] needImport])
{
[[Database shared] import];
}
}
The code above will install your root view controller immediately, then tell the system to invoke a new method finishLaunching at the end of the next pass through the event loop. Since your didFinishLaunchingWithOptions returns quickly, you don't get terminated for taking too long.
You may want to display a loading screen and/or activity indicator before triggering the time-consuming action.
Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.
Apple doesn't allow your didFinishLaunching/didFinishLaunchingWithOptions method to take more than a couple of seconds to complete or the system terminates your app as not responding.
The trick is to do the minimum of setup in didFinishLaunchingWithOptions, and then trigger the time-consuming action after you've returned to the main event loop. Ideally, do you time consuming work asynchronously so the user can start using the app.
The simplest way to release control is to use the method performSelector:withObject:afterDelay:
Something like this:
Code:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Add the view controller's view to the window and display.
self.navController = [[UINavigationController alloc] initWithRootViewController:viewController];
navController.toolbar.barStyle = UIBarStyleBlackOpaque;
[window addSubview:navController.view];
[window makeKeyAndVisible];
//This call returns immediately, then waits until the next time
//through the event loop to invoke the method.
[self performSelector: finishLaunching withObject: nil afterDelay: 0];
return YES;
}
- (void) finishLaunching;
{
if ([[Database shared] needImport])
{
[[Database shared] import];
}
}
The code above will install your root view controller immediately, then tell the system to invoke a new method finishLaunching at the end of the next pass through the event loop. Since your didFinishLaunchingWithOptions returns quickly, you don't get terminated for taking too long.
You may want to display a loading screen and/or activity indicator before triggering the time-consuming action.
Thanks. Though I tried that before and it didn't work. It keeps telling me that I didn't declare the "finishLaunching" was undeclared, but I swear that I did. I was pointed in this same direction by a friend I. I think i'll leave it and look at it in the morning.
Thanks for the help guys. It was really simple though. All I had to do was start animating the UIActivityIndicatorView in my data load method, and stop it during the end of the load.
- (void)viewDidLoad {
[super viewDidLoad];
[indicator startAnimating];
// Load data is a long task, run in in the new thread, otherwise the gui and indicator animating
// will freeze. This new thread doesn't work with GUI at all, it only works on
// data import
[NSThread detachNewThreadSelector:@selector(import) toTarget:self withObject:nil];
}
- (void) import {
// Create new autorelease poll for the thread
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
[[Database shared] import];
[pool release];
// the importig has been finished, so update the gui. The current
// thread doesn't work with the gui, so call updateGUI method of the
// main thread. This thread will be finished because waitUntilDone parameter
// is NO
[self performSelectorOnMainThread:@selector(updateGUI) withObject:nil waitUntilDone:NO];
}
- (void) updateGUI {
// Stop indicator animating and show the navigation controller