Advertise here




Advertise here

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Keep NSTimer running when app is in background (multitasking)

me0007me0007 Posts: 13Registered Users
edited September 2010 in iOS SDK Development
I hope there's an expert out there who can help me with this:

I googled up and down, but could not find any information if there is any way to keep a running NSTimer active when the app is running in the background (iOS 4)?

Thanks for any help!

Steve
Post edited by me0007 on
·

Replies

  • KernelPanicKernelPanic Posts: 25Registered Users
    edited September 2010
    me0007 wrote: »
    I hope there's an expert out there who can help me with this:

    I googled up and down, but could not find any information if there is any way to keep a running NSTimer active when the app is running in the background (iOS 4)?

    Thanks for any help!

    Steve
    I am having same problem and I've managed to setup UILocalNotification and it works fine. But, I get event fired once timer gets to zero (i.e., when current clock is equal to setup) instead of getting event, for instance, every second. Here is sample code:
    - (void)btnSetupNotificationClicked:(id)sender
    {
    	UILocalNotification* pOrderCompletedNotification=[[UILocalNotification alloc] init];
    	if(pOrderCompletedNotification!=nil)
    	{
    		[pOrderCompletedNotification setFireDate:[[NSDate alloc] initWithTimeIntervalSinceNow:5.00]];
    //		[pOrderCompletedNotification setApplicationIconBadgeNumber:1];
    		[pOrderCompletedNotification setTimeZone:[NSTimeZone systemTimeZone]];
    		[pOrderCompletedNotification setSoundName:@";OrderCompleted.m4a"];
    		[pOrderCompletedNotification setAlertBody:@";Order Completed"];
    		[pOrderCompletedNotification setAlertAction:nil];
    		[pOrderCompletedNotification setHasAction:NO];
    	
    		UIApplication* pApplication=[UIApplication sharedApplication];
    		if(pApplication!=nil)
    		{
    			[pApplication scheduleLocalNotification:pOrderCompletedNotification];
    		}
    		else
    		{
    			NSLog(@";Application singleton allocation error.");
    		}
    
    		[pOrderCompletedNotification release];
    		[pApplication release];
    	}
    	else
    	{
    		NSLog(@";Local notification creation error.");
    	}	// if
    }
    
    ·
  • me0007me0007 Posts: 13Registered Users
    edited September 2010
    Thanks for that. I'll give it a try.

    Anyway: does that mean that there's no direct way to keep an NSTimer running when in background?
    ·
  • KernelPanicKernelPanic Posts: 25Registered Users
    edited September 2010
    me0007 wrote: »
    Thanks for that. I'll give it a try.

    Anyway: does that mean that there's no direct way to keep an NSTimer running when in background?

    As my newbie knowledge knows, I (for now) think there is no way.
    ·
  • zero_zero_ Posts: 99Registered Users
    edited September 2010
    maybe you can use some code of
    this tutorial
    <a href="http://itunes.apple.com/it/app/high-altimeter-and-stuff/id368770019?mt=8" target="_blank">high - GPS Tracker and Altimeter Stuff v2.3.1 - new GPS Tracker and other cool Stuff!!!</a>
    ·
  • me0007me0007 Posts: 13Registered Users
    edited September 2010
    zero_ wrote: »
    maybe you can use some code of
    this tutorial

    Thanks, but the problem is not sleeping or deep sleeping. The problem is that an NSTimer stops ticking once an app is in background mode.
    ·
  • zero_zero_ Posts: 99Registered Users
    edited September 2010
    yes i've understand, but if you play a "nosound" during the background you can keepup the timer:d
    <a href="http://itunes.apple.com/it/app/high-altimeter-and-stuff/id368770019?mt=8" target="_blank">high - GPS Tracker and Altimeter Stuff v2.3.1 - new GPS Tracker and other cool Stuff!!!</a>
    ·
  • me0007me0007 Posts: 13Registered Users
    edited September 2010
    zero_ wrote: »
    yes i've understand, but if you play a "nosound" during the background you can keepup the timer:d

    Ah, OK... now I understand. Worth to have a look at it, but as far as I can tell this might be a problem when you want to get the app authorized by Apple...
    ·
  • zero_zero_ Posts: 99Registered Users
    edited September 2010
    me0007 wrote: »
    Ah, OK... now I understand. Worth to have a look at it, but as far as I can tell this might be a problem when you want to get the app authorized by Apple...

    i've not find this authorization limit by Apple:D
    <a href="http://itunes.apple.com/it/app/high-altimeter-and-stuff/id368770019?mt=8" target="_blank">high - GPS Tracker and Altimeter Stuff v2.3.1 - new GPS Tracker and other cool Stuff!!!</a>
    ·
  • me0007me0007 Posts: 13Registered Users
    edited September 2010
    zero_ wrote: »
    i've not find this authorization limit by Apple:D

    OK, I tried that, but it actually does not do what I was looking for. The silent sound is played properly every x seconds (I checked that by replacing it with an audible sound). But: once the app is set to background mode, the app starts to sleep and all running NSTimers, too. When I re-activate the app, I hear that all 'silent sounds' that should have been played while the app was in background mode, are played right one after the other. Also all other NSTimers continue to tick.

    So, this does not help. It does not keep other timers ticking when in background. Too bad... :(
    ·
  • KernelPanicKernelPanic Posts: 25Registered Users
    edited September 2010
    me0007 wrote: »
    OK, I tried that, but it actually does not do what I was looking for. The silent sound is played properly every x seconds (I checked that by replacing it with an audible sound). But: once the app is set to background mode, the app starts to sleep and all running NSTimers, too. When I re-activate the app, I hear that all 'silent sounds' that should have been played while the app was in background mode, are played right one after the other. Also all other NSTimers continue to tick.

    So, this does not help. It does not keep other timers ticking when in background. Too bad... :(

    I also do not have significant progress ... Sorry.
    ·
Sign In or Register to comment.