From the course: Apple watchOS App Development: Advanced APIs

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Solution: A background app

Solution: A background app

From the course: Apple watchOS App Development: Advanced APIs

Start my 1-month free trial

Solution: A background app

- [Narrator] The key I want you to see with this challenge is the application state. When active, update the timer's label. When inactive or in the background, don't update. You need to know the application state, which you can get from the application state property of WKExtenstion. Go to the Interface Controller's start timer method. Give yourself some room by closing the console. Update the label only if the application is active. So I'm going to stick above this, if WKExtension.shared(). applicationState is active, and then put the curly brace at the end of updateLabel. I'm going to get rid of that extra space there. So now it'll only update the label if we have an application state of active. But we've got one more step. The current code invalidates the timer when inactive. Before getting to the background, we always go inactive, so we have to get rid of that code. Go back to the Extension Delegate and comment out the code form the last video to de-activate the code for the timer…

Contents