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
From the course: Apple watchOS App Development: Advanced APIs
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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
(Locked)
Frontmost app state4m 24s
-
(Locked)
The dock and the background states5m 15s
-
(Locked)
The extension delegate7m 25s
-
(Locked)
Challenge: A background app27s
-
(Locked)
Solution: A background app2m 38s
-
Refresh app in the background6m 57s
-
(Locked)
userInfo in background apps7m 48s
-
(Locked)
Update interface with snapshot8m 16s
-
(Locked)
Default snapshots4m 54s
-
(Locked)
-
-
-
-