Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 09-09-2010, 06:59 AM   #1 (permalink)
Registered Member
 
Join Date: Sep 2010
Location: Eastampton, NJ USA
Posts: 34
Fedcis09 is on a distinguished road
Default Help with UIActivityIndicator please

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.

- (BOOL)applicationUIApplication *)application didFinishLaunchingWithOptionsNSDictionary *)launchOptions {

if ([[Database shared] needImport]) {
[[Database shared] import];
} else {
sleep(5);
}

// 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];

return YES;
}

I'd appreciate any help.
Fedcis09 is offline   Reply With Quote
Old 09-09-2010, 07:26 AM   #2 (permalink)
Registered Member
 
Join Date: Feb 2010
Posts: 82
shahab74 is on a distinguished road
Default

Quote:
Originally Posted by Fedcis09 View Post
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.

- (BOOL)applicationUIApplication *)application didFinishLaunchingWithOptionsNSDictionary *)launchOptions {

if ([[Database shared] needImport]) {
[[Database shared] import];
} else {
sleep(5);
}

// 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];

return YES;
}

I'd appreciate any help.
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!!
shahab74 is offline   Reply With Quote
Old 09-09-2010, 08:28 PM   #3 (permalink)
Registered Member
 
Join Date: Sep 2010
Location: Eastampton, NJ USA
Posts: 34
Fedcis09 is on a distinguished road
Default

Quote:
Originally Posted by shahab74 View Post
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?
Fedcis09 is offline   Reply With Quote
Old 09-09-2010, 09:02 PM   #4 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,003
Duncan C has a spectacular aura about
Default

Quote:
Originally Posted by Fedcis09 View Post
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.

- (BOOL)applicationUIApplication *)application didFinishLaunchingWithOptionsNSDictionary *)launchOptions {

if ([[Database shared] needImport]) {
[[Database shared] import];
} else {
sleep(5);
}

// 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];

return YES;
}

I'd appreciate any help.
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.
__________________
Regards,

Duncan C
WareTo

Check out our apps in the Apple App store


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.

See this tutorial on using UIView animations and layer animations:

See this thread on generating random, non-repeating text

Check out a very cool Macintosh Kaleidoscopes app called ScopeWorks that we released to the Mac App store.
Duncan C is offline   Reply With Quote
Old 09-09-2010, 10:51 PM   #5 (permalink)
Registered Member
 
Join Date: Sep 2010
Location: Eastampton, NJ USA
Posts: 34
Fedcis09 is on a distinguished road
Default

Quote:
Originally Posted by Duncan C View Post
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.
Fedcis09 is offline   Reply With Quote
Old 09-12-2010, 02:07 PM   #6 (permalink)
Registered Member
 
Join Date: Sep 2010
Location: Eastampton, NJ USA
Posts: 34
Fedcis09 is on a distinguished road
Default

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

[indicator stopAnimating];
MyAppDelegate *delegate = (MyAppDelegate *)([UIApplication sharedApplication].delegate);

[[UIApplication sharedApplication].keyWindow addSubview:delegate.navigationController.view];
}


Now I just need to figure out how to add a progressview along with it.
Fedcis09 is offline   Reply With Quote
Old 09-12-2010, 02:13 PM   #7 (permalink)
Registered Member
 
Join Date: Sep 2010
Location: Eastampton, NJ USA
Posts: 34
Fedcis09 is on a distinguished road
Default

I was going to start a new thread, but I figured i'd ask here.

Is there a way to set the UIProgressView to the load time of the database?
Is there a default timer that the iOS device utilizes?

If not, should I create a timer, then have it start when the app is loading, and end when the database is done loading?
Fedcis09 is offline   Reply With Quote
Reply

Bookmarks

Tags
database, loading screen, uiactivityview

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 336
10 members and 326 guests
bignoggins, carlandrews, flamingliquid, hzwegjxg, ilmman, jenniead38, linkmx, nadav@webtview.com, stanny
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,657
Threads: 94,116
Posts: 402,889
Top Poster: BrianSlick (7,990)
Welcome to our newest member, jenniead38
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 11:51 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0