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-08-2010, 06:35 AM   #1 (permalink)
Registered Member
 
Join Date: Sep 2010
Posts: 13
me0007 is on a distinguished road
Default Keep NSTimer running when app is in background (multitasking)

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
me0007 is offline   Reply With Quote
Old 09-08-2010, 06:53 AM   #2 (permalink)
Registered Member
 
Join Date: Aug 2009
Location: Ljubljana
Posts: 25
KernelPanic is on a distinguished road
Send a message via Skype™ to KernelPanic
Default

Quote:
Originally Posted by me0007 View Post
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:
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
}
KernelPanic is offline   Reply With Quote
Old 09-08-2010, 11:12 AM   #3 (permalink)
Registered Member
 
Join Date: Sep 2010
Posts: 13
me0007 is on a distinguished road
Default

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?
me0007 is offline   Reply With Quote
Old 09-08-2010, 11:47 AM   #4 (permalink)
Registered Member
 
Join Date: Aug 2009
Location: Ljubljana
Posts: 25
KernelPanic is on a distinguished road
Send a message via Skype™ to KernelPanic
Default

Quote:
Originally Posted by me0007 View Post
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.
KernelPanic is offline   Reply With Quote
Old 09-09-2010, 04:43 AM   #5 (permalink)
Registered Member
 
Join Date: Apr 2010
Location: Milano
Posts: 99
zero_ is on a distinguished road
Default

maybe you can use some code of
this tutorial
zero_ is offline   Reply With Quote
Old 09-09-2010, 05:13 AM   #6 (permalink)
Registered Member
 
Join Date: Sep 2010
Posts: 13
me0007 is on a distinguished road
Default

Quote:
Originally Posted by zero_ View Post
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.
me0007 is offline   Reply With Quote
Old 09-09-2010, 05:22 AM   #7 (permalink)
Registered Member
 
Join Date: Apr 2010
Location: Milano
Posts: 99
zero_ is on a distinguished road
Default

yes i've understand, but if you play a "nosound" during the background you can keepup the timer:d
zero_ is offline   Reply With Quote
Old 09-09-2010, 10:11 AM   #8 (permalink)
Registered Member
 
Join Date: Sep 2010
Posts: 13
me0007 is on a distinguished road
Default

Quote:
Originally Posted by zero_ View Post
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...
me0007 is offline   Reply With Quote
Old 09-09-2010, 11:16 AM   #9 (permalink)
Registered Member
 
Join Date: Apr 2010
Location: Milano
Posts: 99
zero_ is on a distinguished road
Default

Quote:
Originally Posted by me0007 View Post
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
zero_ is offline   Reply With Quote
Old 09-09-2010, 12:47 PM   #10 (permalink)
Registered Member
 
Join Date: Sep 2010
Posts: 13
me0007 is on a distinguished road
Default

Quote:
Originally Posted by zero_ View Post
i've not find this authorization limit by Apple
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...

Last edited by me0007; 09-09-2010 at 01:29 PM.
me0007 is offline   Reply With Quote
Old 09-10-2010, 03:16 AM   #11 (permalink)
Registered Member
 
Join Date: Aug 2009
Location: Ljubljana
Posts: 25
KernelPanic is on a distinguished road
Send a message via Skype™ to KernelPanic
Default

Quote:
Originally Posted by me0007 View Post
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.
KernelPanic is offline   Reply With Quote
Reply

Bookmarks

Tags
background, multitasking, nstimer

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: 334
11 members and 323 guests
bignoggins, carlandrews, flamingliquid, hzwegjxg, ilmman, jenniead38, linkmx, nadav@webtview.com, stanny, v1n2e7t
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:50 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0