WatchKit Apps - An Overview - WatchKit App Development Essentials – First Edition (2015)

WatchKit App Development Essentials – First Edition (2015)

2. WatchKit Apps - An Overview

Before embarking on the creation of a WatchKit app it is important to gain a basic understanding of what a WatchKit app consists of and, more importantly, how it fits into the existing iOS application ecosystem. Within this chapter, a high level overview of WatchKit apps will be provided, together with an outline of how these apps are structured and delivered to the customer.

2.1 What is a WatchKit App?

Prior to the introduction of the Apple Watch family of devices, it was only possible to develop mobile applications for iPhone, iPad and iPod Touch devices running the iOS operating system. With the introduction of the Apple Watch, however, it is now possible for iOS developers to also create WatchKit apps.

In simplistic terms, WatchKit apps are launched on an Apple Watch device either as the result of an action by the user or in response to some form of local or remote notification. Once launched, the WatchKit app presents a user interface on the watch screen displaying information and controls with which the user can interact to perform tasks.

2.2 WatchKit and iOS Apps

It is important to understand that WatchKit apps are not standalone entities. A WatchKit app can only be created as an extension to an existing iOS app. It is not, therefore, possible to create a WatchKit app that is not bundled as part of a new or existing iOS application.

Consider, for example, an iPhone iOS application designed to provide the user with detailed weather information. Prior to the introduction of the Apple Watch, the only way for the user to access the information provided by the app would have been to pick up the iPhone, unlock the device, launch the iOS app and view the information on the iPhone display. Now that information can be made available via the user’s Apple Watch device.

In order to make the information provided by the iOS app available via the user’s Apple Watch, the developer of the weather app would add a WatchKit app extension to the iOS app, design a suitable user interface to display the information on the watch display and implement the logic to display the appropriate weather information and respond to any user interaction. Instead of having to launch the iOS app from the iPhone device to check the weather, the user can now launch the WatchKit app from the Apple Watch and view and interact with the information.

Clearly, the display size of an Apple Watch is considerably smaller than that of even the smallest of iPhone models. As such, a WatchKit app will typically display only a subset of the content available on the larger iPhone screen. For more detailed information, the user would still need to make use of the iOS application.

2.3 The WatchKit Framework

WatchKit apps are made possible by the WatchKit framework which is included as part of the iOS SDK and embedded into both Watch OS (the operating system installed on the Apple Watch) and iOS. The WatchKit framework contains a set of classes that provide the underlying functionality of both the WatchKit extension and WatchKit app. WatchKit, for example, provides the classes that can be used to construct a WatchKit app user interface (such as Button, Label and Slider classes).

WatchKit is also responsible for handling the communication between the iPhone device on which the WatchKit extension is running and the corresponding WatchKit app installed on the Apple Watch.

2.4 Understanding iOS Extensions

Extensions are a feature introduced as part of the iOS 8 SDK release and were originally intended solely to allow certain capabilities of an application to be made available for use within other applications running on the same device. The developer of a photo editing application might, for example, have devised some unique image filtering capabilities and decide that those features would be particularly useful to users of the iOS Photos app. To achieve this, the developer would implement these features in a Photo Editing extension which would then appear as an option to users when editing an image within the Photos app. Other extension types are also available for performing document storage, creating custom keyboards and embedding information from an application into the iOS notification panel.

With the introduction of the Apple Watch and WatchKit, however, the concept of extensions has now been extended to make the functionality of an iOS app available in the form of a WatchKit app.

Extensions are separate executable binaries that run independently of the corresponding iOS application. Although extensions take the form of an individual binary, they must be supplied and installed as part of an iOS application bundle. The application with which an extension is bundled is referred to as the containing app or parent app. The containing app must provide useful functionality and must not be an empty application provided solely for the purpose of delivering an extension to the user.

Once an iOS application containing a WatchKit extension has been installed on an iPhone device, it will be accessible from the Apple Watch device paired with that iPhone. When the user launches a WatchKit app on a watch device, the WatchKit framework will launch the corresponding WatchKit extension on the paired iPhone device, establish communication between the two entities and then begin the app initialization process.

2.5 Basic WatchKit App/Extension Structure

Simply by the nature of its physical size, an Apple Watch is always going to be resource constrained in terms of storage and processing power when compared to an iPhone. As previously outlined, the implementation of a WatchKit app is divided between the WatchKit app installed on the watch and the WatchKit extension bundled with the iOS app on the iPhone device. This raises the question of how the responsibilities of providing the functionality of the WatchKit app are divided between the app and the extension.

By necessity, the WatchKit app needs to be small and efficient. In fact, the WatchKit app bundle installed on the Apple Watch device consists solely of the storyboard file containing the user interface and corresponding resources (such as image and configuration files).

All of the code for providing the functionality of the WatchKit app and responding to user interaction is contained within the WatchKit extension and executed on the iPhone, with the WatchKit framework handling the communication between the app and the extension. This communication primarily takes the form of responding to user interactions (for example notifying the extension that a button was pressed in the user interface), making changes to the user interface on the watch (such as changing the text displayed on a label) and transferring data.

This separation ensures that WatchKit apps remain small and that the resource intensive code execution is performed almost entirely on the iPhone device.

2.6 WatchKit App Entry Points

There are number of different ways in which the user may enter a WatchKit app, each of which will be detailed in later chapters and can be summarized as follows:

· Home Screen – Once installed, the WatchKit app will be represented by an icon on the home screen of the Apple Watch display. When this icon is selected by the user the app will load and display the main user interface scene.

· Glance – When developing a WatchKit app, the option is available to add a Glance interface to the app. This is a single, non-scrollable, read-only scene that can be used to display a quick-look summary of the information normally presented by the full version of the app. Glances are accessed when the user performs an upward swiping motion on the watch display and, when tapped by the user, launch the corresponding WatchKit app.

· Notifications – When a notification for a WatchKit app appears on the Apple Watch device, the app will be launched when the notification is tapped.

2.7 Summary

A WatchKit app is an application designed to run on the Apple Watch family of devices. A WatchKit app cannot be a standalone application and must instead be created as an extension of an existing iOS application. WatchKit apps and extensions are built in Xcode using the WatchKit framework which, in turn, provides the classes necessary to build WatchKit apps. The WatchKit app is installed on the Apple Watch device and consists of a storyboard file containing the user interface of the app together with a set of resource files. The WatchKit extension, on the other hand, is bundled with the corresponding iOS app and resides and executes on the iPhone device. The extension is a separate binary from the main iOS app and contains all of the code logic to implement the behavior of the WatchKit app. When the app is launched on the Apple Watch, the WatchKit framework launches the corresponding extension on the iPhone device and handles the communication between the app and extension.