Preface

Welcome to Learning WatchKit Programming, Second Edition!

This is an exciting time to be a programmer, as we are witnessing a new era of wearables. Although the Apple Watch is not the first wearable device in the market, its launch signified the intention of Apple to enter the wearable market in a big way. After successfully changing various industries—music, computer, phone, and mobile computing—Apple looks set to change the wearable industry. And nobody is taking this lightly.

As with the iPhone, much of the usefulness and functionality of the Apple Watch device actually come from the creativity of the third-party developers. In the early days of the iPhone, Apple restricted all third-party apps to web applications, as it wanted to retain the monopoly on developing natively for the device. However, due to the overwhelming protests of developers, Apple finally relented by releasing an SDK to support third-party apps. It was this decision that changed the fate of the iPhone; the iPhone would never have been so successful without the ability to support third-party apps.

When the Apple Watch was announced, Apple was quick to learn its lesson and realized that the success of the Apple Watch largely depends on the availability of apps that support it. Hence, before the release of the Apple Watch, the SDK was made available to developers to have a hand in developing Apple Watch apps.

Barely two months after the Apple Watch was made available for sale, Apple announced the second version of the Apple Watch OS, aptly named watchOS 2. Unsurprisingly, watchOS 2 now supports native apps and comes with a slew of new features.

The book you are holding in your hands right now (or reading on your phone or tablet) is a collection of tutorials that help you navigate the jungle of Apple Watch programming. This book contains all the fundamental topics that you need to get started in Apple Watch programming. In particular, this second edition has been fully updated to cover watchOS 2 programming.

Because this is a book on Apple Watch programming, I make a couple of assumptions about you, the reader:

Image You should already be familiar with the basics of developing an iOS application. In particular, concepts like outlets and actions should not be new to you.

Image You should be comfortable with the Swift programming language, but see the next section on how to get started with Swift if you are new to it.

What You’ll Need

To get the most out of this book, note the following:

Image You need a Mac, together with Xcode.

Image Your Mac should be running at least Mac OS X Yosemite (v10.10) or later.

Image You can download the latest version of Xcode from the Mac App Store. All of the code samples for this book have been tested against Xcode 7.

Image If you plan to test your apps on a real device, you need to register to become a paying Apple developer (https://developer.apple.com/programs/). The program costs $99 per year for individuals. Once registered, you can register your Apple Watch’s UDID with Apple (necessary for testing on Apple Watch). The Apple Watch works only with iPhone 5, iPhone 5c, iPhone 5s, iPhone 6, iPhone 6 Plus, iPhone 6s, and iPhone 6s Plus (or newer versions of the iPhones).

Image Most of the code samples in this book can be tested and run on the iPhone Simulator without the need for a real device or Apple Watch. However, for some code examples, you need access to a real Apple Watch (for example, to access the hardware features like accelerometer, microphone, etc.).

Image A number of examples in this book require an Internet connection in order to work, so ensure that you have an Internet connection when trying out the examples.

Image All of the examples in this book are written in Swift 2.0. If you are not familiar with Swift, you can refer to Apple’s web page on Swift at https://developer.apple.com/swift/resources/.

How This Book Is Organized

This book is styled as a tutorial. You try out the examples as I explain the concepts. This is a proven way to learn a new technology, and I strongly encourage you to type in the code as you work on the examples.

Image Chapter 1, “Getting Started with WatchKit Programming: In this chapter, you learn about the architecture of Apple Watch applications and how it ties in with your iOS apps. Most importantly, you get your chance to write a simple Apple Watch app and deploy it onto the Apple Watch Simulator.

Image Chapter 2, “Apple Watch Interface Navigation: In this chapter, you dive deeper into how your Apple Watch application navigates between multiple screens. You get to see how data is passed between screens and how to customize the look and feel of each screen.

Image Chapter 3, “Responding to User Actions: Designing the user interface (UI) for your Apple Watch application is similar to designing for iPhone apps. However, space is at a premium on the Apple Watch, and every millimeter on the screen must be put to good use in order to convey the exact intention of your app. In this chapter, you learn how to use the various UI controls in the Apple Watch to build your application. You will start off with the controls with which the user interacts.

Image Chapter 4, “Displaying and Gathering Information: While Chapter 3 covers the various controls with which the user interacts through the tap gesture, this chapter continues to explore the various controls available in the WatchKit framework, focusing on controls that display information, as well as controls that gather information.

Image Chapter 5, “Accessing the Apple Watch Hardware: In watchOS 1, Apple did not provide third-party developers access to the various hardware features of the Apple Watch, such as accelerometer, microphone, and Taptic Engine. However, in watchOS 2, Apple has exposed some of these features to developers so that they can create more exciting watch apps. In this chapter, you learn how to access some of these hardware features and see how they can be useful to the apps you are building.

Image Chapter 6, “Programming Complications: A complication is a function on a timepiece that does more than just tell the time. Complications on a timepiece include alarms, tachymeters, chronographs, calendars, and so on. In watchOS 2, third-party apps can now also display data in watch face complications. In this chapter, you learn the process of creating an application that displays complication data.

Image Chapter 7, “Interfacing with iOS Apps: This chapter discusses the Watch Connectivity Framework, a set of APIs that allow the containing iOS app to communicate with the watch app (and vice versa). In addition to discussing how apps intercommunicate, this chapter also discusses how to use location services in your watch app, as well as how to consume web services. Last, but not least, this chapter ends with a discussion on persisting data on your watch.

Image Chapter 8, “Displaying Notifications: In this chapter, you learn how to display notifications on your Apple Watch. Notifications received by the iPhone are sent to the Apple Watch, and you have the chance to customize the notifications so that you can display their essence quickly to the user.

Image Chapter 9, “Displaying Glances: Glances on the Apple Watch provide the user a quick way to gather information from apps. For example, Instagram’s glance on the Apple Watch may show the most recently shared photo, and Twitter may show the latest trending tweets. In this chapter, you learn how to implement glances for your own apps.

About the Sample Code

The code samples in this book are written to provide the simplest way to understand core concepts without getting bogged down with details like beautifying the UI or detailed error checking. The philosophy is to convey key ideas in the simplest manner possible. In real-life apps, you are expected to perform detailed error handling and to create a user-friendly UI for your apps. Although I do provide several scenarios in which a certain concept is useful, it is ultimately up to you, the reader, to exercise your creativity to put the concepts to work, and perhaps create the next killer app.

Getting the Sample Code

To download the sample code used in this book, visit the book’s web page on informIT.com at http://informit.com/title/9780134398983, click the Extras tab, and register your book.

Contacting the Author

If you have any comments or questions about this book, drop me an email at [email protected], or stop by my web site at http://learn2develop.net.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.30.62