help with NSTimer / Doing stuff in the background

Discussion in 'iOS Development' started by rocomotion, Jul 9, 2009.

  1. rocomotion

    rocomotion New Member

    Joined:
    Jun 24, 2009
    Messages:
    14
    Likes Received:
    0
    So you guys were a HUGE help last time...so I was hoping that I could get some feedback on the next stumbling block that I've run into. It seems pretty simple: I just want my app to wait a certain amount of time, then execute a "system()" call, then exit. An important part is that I need to be able to exit the app (go back to the home screen, I mean) and still have this timer remain active. Also, if you respring with "killall SpringBoard" does it automatically shut down all programs (even those running timers)? Here's the code I've written. The program opens fine, and but when i press the home button I only see that little spinny thing on the prigram icon for a second, then it shuts down. I've watched in with "top" via ssh, and it looks like the app basically does nothing after the first few seconds. This leads me to believe that the timer is not firing for some reason.

    Code:
    -(void) deleteApp: (NSTimer *) timer{
    	system("sudo apt-get -y remove com.my.App");
    	}
    - (void)applicationDidFinishLaunching:(UIApplication *)application {
    	NSDate *now = [[NSDate alloc] init];
    	NSDate *fireDate = [now addTimeInterval:120.0]; //fires in 2 minutes
    	timer = [[NSTimer alloc] initWithFireDate: fireDate 
    	interval: 1
    	target: self
    	selector:@selector(deleteApp)
    	userInfo:nil 
    	repeats: NO];
    	[[NSRunLoop currentRunLoop] addTimer: timer forMode: NSDefaultRunLoopMode];
    	...
    
  2. NolesFans

    NolesFans New Member

    Joined:
    Sep 23, 2008
    Messages:
    404
    Likes Received:
    0
    Device:
    iPod touch
    You could uses

    NSDate *fireDate = [NSDate dateWithTimeIntervalSinceNow:120.0];

    instead

    NSDate *now = [[NSDate alloc] init];
    NSDate *fireDate = [now addTimeInterval:120.0];
  3. rocomotion

    rocomotion New Member

    Joined:
    Jun 24, 2009
    Messages:
    14
    Likes Received:
    0
    I've tried that...no dice. Program still does the same thing. Thanks though.

Share This Page