WatchKit Overview

Few days ago Apple released long-awaited SDK for Apple Watch. Device itself is scheduled to be released early next year (spring most likely). However, Apple as usually granted registered developers an early access to set of libraries and tools for developing application. It is embedded into Xcode 6.2 Beta and called WatchKit. I have put together a quick overview of SDK, describing what developers can and cannot do with Apple Watch.

Surprisingly for some, we can actually do a lot. Although WatchKit framework reference looks scarce, developers can actually create applications for the Apple Watch. However, they do not actually run on the device. If you watched Apple's presentation closely you had noticed that Apple Watch requires an iOS device to work with. I assume it can work as a watch even on there own. But in order to get most interesting features out of Apple Watch people are required to have an iPhone in their pocket. This is the device to actually run the code. Apple Watch acts merely as a display and input device.

Application Architecture

Good place to start with WatchKit is sample application WatchKit Catalog. Application for WatchKit needs companion iOS application. In Xcode we need to setup 3 different targets:

  1. A plain old iOS Application.

  2. WatchKit extension - the code, that will run on iOS device, when application is launched on watch. It includes all source code for Apple Watch view controllers (WKInterfaceController subclasses).

  3. WatchKit application - application for the Apple Watch itself. As I mentioned previously Apple Watch doesn't run any application code it merely presents views and processes input. Thus WatchKit application target should only include stuff for presenting views - storyboards and images.

In WatchKit Catalog sample application the setup looks like this:

WatchKit targets can be added to existing project in the same way as any other targets are added to Xcode. Except you don't need to add targets separately. Instead there is a single option "Watch App" in "Add target" menu. It will create both targets automatically.

iOS application bundle from pure technical point of view is simply a container for WatchKit extension code. iOS application and WatchKit extension have a completely non-related life cycles: running each of them has no effect on the other. They are running in a separate sandboxed environments (although Apple suggests setting them up in the shared application group, so they can access each other's data on disk). Technically WatchKit application can do everything on its own, reducing iOS application to a dummy with a single static screen. However, that would contradict Apple Watch Human Interface Guidelines:

A Watch app complements your iOS app; it does not replace it.

WatchKit application is started as soon as user explicitly starts it either from Apple Watch home screen or from notification or glance (more on this later). And stopped as soon as user closes it. iOS application has no way of learning about the current WatchKit application state.

Xcode 6.2 includes a simulator for Apple Watch as a separate window in an old iOS Simulator application.

Simulator lacks a home screen, the only way to start an WatchKit application is from Xcode. When you add targets for WatchKit applications several schemes are automatically added to Xcode:

"Glance" and "Notification" are special schemes for testing Glances and Notifications. "Watch App" target will start a Watch application like if user has started it on his Apple Watch manually.

User Interface

Apple Watch application doesn't get to use rich UIKit capabilities. Instead, a small library of components (subclasses of WKInterfaceObject) is available. They might seem poor in comparison with UIKit, but that's because Apple Watch user interfaces are not intended to be as rich as iPhone's.

Developers and designers are strongly advised to study Apple Watch Human Interface Guidelines. Apple also kindly provides Apple Watch Design Resources at the bottom of this page. This a set of PSD images and templates for Apple Watch.

Weak spot of the Apple Watch UI is animation. Developers don't get anything even remotely equivalent to Core Animation. No custom drawing either. Static images only. Create multiple images and flip through them using NSTimer. That's what Apple does in Lister application sample code.

Glances

User has one more way to interact with Apple Watch application additionally to simply starting it from home screen. It is called "Glance". Glance is basically a single screen widget, presenting application most essential data. User can swipe through the application glances from his home screen. Tapping on the glance opens the relevant Apple Watch application.

Technically Glance is a WKInterfaceController. Application provides Glance by defining a Glance Entry Point in storyboard file.

Notifications

Apple Watch will automatically present all push and local notifications for the iOS application. WatchKit application can customize the notification interface by subclassing WKUserNotificationInterfaceController. Application can provide different interfaces for different notification categories (starting with iOS 8 notification payload can contain "category" string identifier).

Notification controller provides 2 views: static and optional dynamic. Static view is meant to only display data from notification, while dynamic if possible extends that data by providing more data from additional source (e.g. showing some relevant image).

Notification controllers can be set up in storyboard by setting Notification Category Entry Points.

Apple Watch Sensors

Apple Watch will include a handlful of sensors. Apple promised at least: accelerometer, barometer and heart rate monitor. WatchKit doesn't provide any direct access to those sensors. Although, application probably can obtain at least some of the processed data via HealthKit framework. That's still a mistery, however, because actual devices are not yet available.

Conclusion

This all is quite exciting. A wide range of application can benefit from adding Apple Watch extension. There probably not that much opportunities for new market Apple Watch oriented applications. WatchKit is useless unless you have a solid and usefull iOS application. But still there is some space for smart Apple Watch ideas.

Moreover, Apple press release suggests that we will be getting access to even more Apple Watch functionality next year. "Fully native apps for Apple Watch" they say.

Vitaliy Ivanov Technical Director at Factorial Complexity