WatchKit App Development Essentials First Edition
2015 Neil Smyth. All Rights Reserved.
This book is provided for personal use only. Unauthorized use, reproduction and/or distribution strictly prohibited. All rights reserved.
The content of this book is provided for informational purposes only. Neither the publisher nor the author offers any warranties or representation, express or implied, with regard to the accuracy of information contained in this book, nor do they accept any liability for any loss or damage arising from any errors or omissions.
This book contains trademarked terms that are used solely for editorial purposes and to the benefit of the respective trademark owner. The terms used within this book are not intended as infringement of any trademarks.
Rev 1.0
Table of Contents
1. Start Here
Announced in September 2014, the Apple Watch family of devices is Apples first foray into the market of wearable technology. The introduction of this new device category was accompanied by the release of the WatchKit framework designed specifically to allow developers to build Apple Watch app extensions to iPhone-based iOS apps.
WatchKit App Development Essentials is intended for readers with some existing experience of iOS development using Xcode and the Swift programming language. Beginning with the basics, this book provides an introduction to WatchKit apps and the WatchKit app development architecture before covering topics such as tables, navigation, user input handling, working with images, maps and menus.
More advanced topics are also covered throughout the book, including communication and data sharing between a WatchKit app and the parent iOS app, working with custom fonts and the design and implementation of custom notifications.
As with all the books in the Development Essentials series, WatchKit App Development Essentials takes a modular approach to the subject of WatchKit app development for the Apple Watch, with each chapter covering a self-contained topic area consisting of detailed explanations, examples and step-by-step tutorials. This makes the book both an easy to follow learning aid and an excellent reference resource.
1.1 Source Code Download
The source code and Xcode project files for the examples contained in this book are available for download at:
http://www.ebookfrenzy.com/retail/watchkit/
1.2 Feedback
We want you to be satisfied with your purchase of this book. If you find any errors in the book, or have any comments, questions or concerns please contact us at .
1.3 Errata
Whilst we make every effort to ensure the accuracy of the content of this book, it is inevitable that a book covering a subject area of this size and complexity may include some errors and oversights. Any known issues with the book will be outlined together with solutions at the following URL:
http://www.ebookfrenzy.com/errata/watchkit.html
In the event that you find an error not listed in the errata, please let us know by emailing our technical support team at .
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 users Apple Watch device.
In order to make the information provided by the iOS app available via the users 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.
Next page