Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

mrl72

macrumors regular
Original poster
Apr 20, 2008
221
19
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.
 
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?
 
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.
 
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]
 
Excellent, thank you. I did that and it worked great!
 
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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.