Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Feb 4, 2011, 06:51 AM   #1
mrl72
macrumors regular
 
Join Date: Apr 2008
NSTimer questions

Hi all, I have a couple of questions regarding the NSTimer.

1. From my main thread I call two timers, one plays an image slideshow in a 10 second loop, and the other downloads images from a server. When the second timer is running, the slideshow pauses until it completes. Any idea why this would happen?

2. I want to add the ability to automatically kick off a method if the user quits the apps and returns after a specified time. Can this be achieved via a timer or is there some kind of built in method that I can use?

Cheers.
mrl72 is offline   0 Reply With Quote
Old Feb 4, 2011, 06:58 AM   #2
NickFalk
macrumors 6502
 
Join Date: Jun 2004
Quote:
Originally Posted by mrl72 View Post
Hi all, I have a couple of questions regarding the NSTimer.

1. From my main thread I call two timers, one plays an image slideshow in a 10 second loop, and the other downloads images from a server. When the second timer is running, the slideshow pauses until it completes. Any idea why this would happen?

2. I want to add the ability to automatically kick off a method if the user quits the apps and returns after a specified time. Can this be achieved via a timer or is there some kind of built in method that I can use?

Cheers.
1. Some code-snippets would be nice.

2. How about using an NSDate as a timestamp, storing it and then comparing it with the time the user reenters the app?
NickFalk is offline   0 Reply With Quote
Old Feb 4, 2011, 08:05 AM   #3
mrl72
Thread Starter
macrumors regular
 
Join Date: Apr 2008
Thanks Nick. I'll paste some code shortly.

In regards to your second answer, how would this work exactly? Is it case of having a timer run repeatedly (say every minute) that simply looks for that date and then the date is set in applicationDidEnterBackground and/or applicationWillTerminate methods?

Cheers.
mrl72 is offline   0 Reply With Quote
Old Feb 4, 2011, 08:24 AM   #4
NickFalk
macrumors 6502
 
Join Date: Jun 2004
Quote:
Originally Posted by mrl72 View Post
Thanks Nick. I'll paste some code shortly.

In regards to your second answer, how would this work exactly? Is it case of having a timer run repeatedly (say every minute) that simply looks for that date and then the date is set in applicationDidEnterBackground and/or applicationWillTerminate methods?

Cheers.
Nope you just make an NSDate with the current time at the time of exit. When the user return you compare the stored exitDate to the time the time at the moment. Something along these lines:

NSTimeInterval elapsedTime = [reEnterDate timeIntervalSince: exitDate]
NickFalk is offline   0 Reply With Quote
Old Feb 4, 2011, 08:56 AM   #5
mrl72
Thread Starter
macrumors regular
 
Join Date: Apr 2008
Excellent, thank you. I did that and it worked great!
mrl72 is offline   0 Reply With Quote
Old Feb 4, 2011, 10:04 AM   #6
dejo
Moderator
 
dejo's Avatar
 
Join Date: Sep 2004
Location: The Centennial State
Quote:
Originally Posted by mrl72 View Post
1. From my main thread I call two timers, one plays an image slideshow in a 10 second loop, and the other downloads images from a server. When the second timer is running, the slideshow pauses until it completes. Any idea why this would happen
Sounds like what you are doing in the second bit is blocking the main run loop. And the UI can only be updated from the main thread. You should find a way to put your image downloading into the background.
__________________
dejo is online now   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
NSTimer Alternatives adimanic iPhone/iPad Programming 1 Jan 4, 2014 12:04 AM
Problem with Model window and NSTimer. staziz Mac Programming 3 Jul 15, 2013 01:13 AM
NStimer in Background erdinc27 iPhone/iPad Programming 6 May 11, 2013 07:21 AM
NSTimer erroneously invalidated ramy1989 Mac Programming 4 Dec 21, 2012 03:22 PM
NSTimer not firing eddjc Mac Programming 6 Jul 28, 2012 03:30 PM

Forum Jump

All times are GMT -5. The time now is 12:03 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC