WatchKit: The First Glance at Glances
“The job of your glance interface controller is to set the contents of the glance. Glances do not support interactivity, and tapping on a glance automatically launches your Watch app.” – WatchKit Programming Guide
By swiping up from the watch face on the Apple Watch, the user will be able to page through Glances from their favorite apps. Glances are very simple one page summaries of useful information (e.g. the weather).
I highly recommend reading the Glances part of the Apple Watch HIG as well as the Glance Essentials from the WatchKit Programming Guide before getting started.
Setup Your Watch App
Follow the steps from my “Hello World” WatchKit Tutorial to get started. The only difference is that when you get to the part when you’re creating the Watch App Target, check the Include Glance Scene check box:
In your Interface.storyboard you will now see a Glance Interface Controller. You’ll also see a pre-made GlanceController file in your WatchKit Extension:
Run the app via your Watch App Target to make sure everything is set up correctly!
Style Your Glance
At this point you can use the storyboard for the initial setup of your Glance. However, as mentioned in the Glance Essentials section of the WatchKit Programming Guide:
Do not include interactive controls in your interface. Interactive controls include buttons, switches, sliders, and menus.
I’m going to make a Glance that just shows me a kitten posted by @BabyAnimal this morning:
Of course you can also add IBOutlets to your interface Image and Label elements and populate them via the GlanceController if needed.
Once you’ve set up your interface, run the app. If you’re confused, you’re not alone! Remember, on the Apple Watch, the user will be able to swipe up to see the Glances. Unfortunately, the Apple Watch Simulator is not set up to have this interaction, so you’ll have to do some additional setup to actually test out your Glance…
Setup Glance Scheme
To actually view and debug your Glance, you’ll have to configure a separate build scheme as outlined in the Configuring Your Xcode Project section in the WatchKit Programming Guide:
- Select your existing Watch app scheme.
- Select Edit Scheme from the scheme menu.
- Duplicate your existing Watch app scheme and give the new scheme an appropriate name.For example, give it a name like “Glance – My Watch app” to indicate that the scheme is specifically for running and debugging your glance.
- Select Run from the left column of the scheme editor.
- In the Info tab, select the appropriate executable.
See Your Glance
Finally, select your Glance target and Run!
Have a Good Morning!
Launch Your App
By tapping on your Glance, the user will be able to directly launch your Watch App!
You can find the the sourcecode on Github here.