1

I am first in watchkit and I am going to make alarm app. After start app, app should play sound every some seconds(user can set this time interval). I am using Timer to count time interval, and if count time is 0 then play sound and resent timer again.

But before play sound, if watch goes to sleep mode then timer is stopped and so no play sound, that is, no alarm. Apple says timer is not working on sleep mode, but working on emulator. I am trying to use WKInterfaceTimer. It's working in sleep mode, but there is no event to run a function. This is only count timer. No invoke event to play sound and so on. Then is there any way to implement alarm like app? Is there any method to use timer in sleep mode? Thanks for your advance.

Water Flower
  • 377
  • 7
  • 23

1 Answers1

0

The functioning of the simulator and actual watch device differs. For your case, You can just declare a optional Timer in your interface controllers using

Timer(fireAt: <#T##Date#>, interval: <#T##TimeInterval#>, target: <#T##Any#>, selector: <#T##Selector#>, userInfo: <#T##Any?#>, repeats: <#T##Bool#>)

fire the timer when the ControllerIsActivated and set it to nil when the controllerIsDeactivated i.e in sleep.

Try perform the same in Using ExtensionDelegate Methods like didEnterForeground and WillEnterBackground.

Pranay Chander
  • 461
  • 5
  • 12