1

I am editing my original post, as I did receive a reply on the Apple Forums.

In summary: You cannot use NSTimer in Background (even if it works in the Simulator). If a timer functionality is needed then the allowed practice is use UILocalNotification. So, I am re-writing my code accordingly.

Wanted to share this in case others faced/will face the same issue.

  • have you enabled backgorund mode? – johny kumar Dec 25 '14 at 06:05
  • Thank you Johny, but it seems not! Grateful for any links/guidance on how to do this in Swift. – AspiringDeveloper Dec 25 '14 at 06:22
  • Are these what I need: applicationDidEnterBackground & applicationWillEnterForeground? If yes, how exactly are they used inside the Swift code? Do I need some code prior (like in viewDidLoad, etc.)? – AspiringDeveloper Dec 25 '14 at 06:30
  • http://www.raywenderlich.com/29948/backgrounding-for-ios this may help you. – johny kumar Dec 25 '14 at 07:11
  • Yes, I did check Ray's website tutorial (I am actually a subscriber) but the modes mentioned are the same as in Apple's reference, in Obj-C and none mentions a timer function. I'll keep researching. Thanks again. – AspiringDeveloper Dec 25 '14 at 10:11
  • http://stackoverflow.com/questions/22628922/how-to-run-nstimer-in-background-beyond-180sec-in-ios-7 and http://stackoverflow.com/questions/9220494/how-do-i-make-my-app-run-an-nstimer-in-the-background/9623490#9623490 check this. – johny kumar Dec 25 '14 at 12:04
  • Current status: Xcode simulator behaves as expected (Home button does NOT suspend, and the timer keeps counting down and plays audio file at end). On real iPhone, the Home button suspends the timer. Researching why the real iPhone does not replicate the Simulator. – AspiringDeveloper Dec 27 '14 at 01:18

0 Answers0