Book Image

Apple Watch App Development

By : Steven F. Daniel
Book Image

Apple Watch App Development

By: Steven F. Daniel

Overview of this book

With the increasing amount of new wearable devices hitting the market, wearables are the next wave of mobile technology. With the release of Apple's WatchKit SDK, a whole new world of exciting development possibilities hasopened up. Apple Watch App Development introduces you to the architecture and limitations of the Apple Watch platform, followed by an in-depth look at how to work with Xcode playgrounds. Here, we'll introduce you to the Swift programming language so you can quickly begin developing apps for the Apple Watch platform with the WatchKit framework and the Xcode Development IDE. We then discuss more advanced topics such as Notifiations, Glances, Closures, Tuples, Protocols, Apple pay, and using Swift playgrounds, with each concept backed up with example code that demonstrates how to properly execute it. We also show you how to package and deploy your Watch application to the Apple AppStore. By the end of this book, you will have a good understanding of how to develop apps for Apple Watch platform using the WatchKit framework and Swift 2.0.
Table of Contents (19 chapters)
Apple Watch App Development
Credits
About the Author
Acknowledgements
About the Reviewer
www.PacktPub.com
Preface
Index

Preface

With the increasing amount of new wearable devices hitting the market, wearables are the next wave of mobile computing technology. After the release of Apple's WatchKit SDK, a whole new world of exciting development possibilities awaits us.

Apple Watch App Development provides you with a practical approach that shows you how to develop and build Apple Watch apps using the Xcode Integrated Development Environment. You will be introduced to the architecture and limitations of the Apple Watch platform, followed by an in-depth look at the Swift programming language, where we talk about closures, tuples, protocols, delegates, and how to work with Xcode playgrounds.

We also discuss more advanced topics, such as notifications, glances, Apple Pay, as well as the Core Location and Watch Connectivity frameworks to synchronize data between the Apple Watch and the iPhone using the WatchKit platform. By the end of this book, you will have a good understanding of how to build real-world applications for the Apple Watch platform using the WatchKit framework and Swift 2.0.

In this book, I have tried my best to keep the code simple and easy to understand by providing a step-by-step approach with lots of screenshots at each step to make it easier to follow. You will soon be mastering the different aspects of Apple Watch wearable programming, as well as mastering the technology and skills that are needed to create your own applications for the Apple Watch platform.

Feel free to contact me at for any queries, or just drop me an e-mail to say "Hello".

What this book covers

Chapter 1, Introducing the Swift Programming Language, focuses on how to go about signing up to the Apple Developer program, as well as downloading and installing the Xcode development tools. We will cover Xcode playgrounds before moving on to learning the basics of the Swift programming language and some of the new additions to Swift with Swift 2.

Chapter 2, Understanding Apple Watch, introduces you to the WatchKit platform architecture and the application life cycle, as well as a list of the WatchKit classes that make up the WatchKit platform. You'll learn about some of the limitations behind the WatchKit platform architecture, as well as some of the new additional features that are a part of watchOS 2. You will then go on to learn about the Apple Watch Human Interface Guidelines.

Chapter 3, Exploring WatchKit Controls, introduces you to some of the controls that come as a part of the WatchKit platform. You will learn how to work with Xcode's Interface Builder to build the visual interface for our first WatchKit application. You will also learn how to use Outlets to bind objects to the Interface Builder objects and create some Action events to respond to these objects when tapped by the user to provide visual feedback.

Chapter 4, Using the Core Location and Watch Connectivity Frameworks, delves deeper into learning more about the WatchKit framework and the new layout system using groups. You'll learn about the MapKit and WKInterfaceMap frameworks. You will also learn how you can use these to incorporate mapping capabilities within your WatchKit apps using the Watch Connectivity framework to send geographical location-based coordinates between your iOS app and WatchKit to display the user's current location on the Apple Watch.

Chapter 5, Navigating Around in WatchKit, introduces you to some of the ways that you can navigate within the watch face user interface. You'll learn the differences between page-based, modal, and hierarchical navigation, and when to use them. You will then learn how to use the HealthKit framework to access health-related information and share this information between the iOS device and the WatchKit extension to display a user's current heart rate, blood type, and number of steps taken for a particular day.

Chapter 6, Implementing Tables within Your App, focuses on teaching you how to create applications that handle Apple Pay payments using the PassKit framework. You will learn how to pass information between the iOS device and the WatchKit extension. You will also learn how to use the WKInterfaceTable controller, how to set it up and configure it, as well as how to display information from a JSON file.

You will learn how to use the WKInterfaceTable methods to determine when a row has been selected by the user and respond to this action.

Chapter 7, Adding Menus to Your App, introduces you to WatchKit menus, and how you can incorporate them into your own applications, as well as respond to them based on what the user has chosen. We end the chapter by covering how you can use the Taptic Engine to integrate haptic feedback in your own applications.

Chapter 8, Incorporating the Glance Interface in Your App, shows you how to effectively incorporate WatchKit glances within an existing WatchKit application by creating a custom GlanceInterfaceController class to display information within the glance interface. You'll learn about the glance interface guidelines, which outline the guidelines and principles that you need to follow when designing your layouts for the different Apple Watch screen sizes.

Chapter 9, Incorporating Notifications within Your App, explains how to incorporate and configure local and remote notifications within an existing Apple Watch application. You will learn about the notifications life cycle and the differences between static and dynamic interfaces.

You will learn about the Apple Push Notification service (APNs) and how you can use this to send and receive information by responding to button actions when a user taps on the button. You will learn about the notification interface guidelines, which outlines the guidelines and principles that you need to follow when designing your notifications.

Chapter 10, Image Compression and Animation, shows you how to add images to the image assets catalog, and then start to build a simple WatchKit application that showcases how to animate a series of images within the WatchKit user interface.

You'll learn about the Application Transport Security (ATS) protocol that Apple introduced with the release of iOS 9, which forces developers to provide secure connections between your Apple Watch apps that communicate over HTTPS. We will also be covering how to properly configure our Apple WatchKit extension, as well as learn the best ways of handling and compressing large image files when these are downloaded from an external website so to increase performance.

Chapter 11, Packaging and Deploying Your App, focuses on how to submit your application to the Apple App Store, and share your creations with the rest of the community. You'll learn how to set up your iOS development team as well as the development and distribution certificates.

Finally, you will learn how to use the Instruments application to profile your application to eliminate performance bottlenecks. You will also learn how to package your application using Xcode and deploy this to iTunes Connect so that you can download and test on your Apple Watch device.

What you need for this book

The minimum requirement for this book is an Intel-based Macintosh computer running OS X El Capitan 10.11. We will be using Xcode 7.3, which is the Integrated Development Environment (IDE) that is used to create applications for iOS, watchOS, and tvOS. Almost all projects that you will create with the help of this book will work and run on the iOS Simulator. However, some projects will require an Apple Watch and an iPhone to work correctly.

You can download the latest version of Xcode from http://developer.apple.com/xcode/.

Who this book is for

This book is intended for developers who have a working experience of application development principles on the Mac OS X and/or iOS platforms and wish to expand their knowledge to develop applications for the Apple Watch using the Swift programming language and the WatchKit framework. It is assumed that you are familiar with object-oriented programming (OOP) and have some experience with Swift.

Conventions

In this book, you will find a number of text styles that distinguish between different kinds of information. Here are some examples of these styles and an explanation of their meaning.

Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "Launch the Keychain Access application, which can be found in the /Applications/Utilities folder."

A block of code is set as follows:

Override func willActivate() {
     Super.willActivate()
     guessLabel.setText("Your Guess is: + String(Int(yourGuess)))
     guessLabel.setTextColor(UIColor.yellowColor())
}

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

// Method to handle the Encryption
func encryptString(str: String, withPassword password: String) throws -> String {
    
    guard password.characters.count > 0  else { throw  
    EncryptionError.Empty }
    guard password.characters.count >= 5 else { throw  
    EncryptionError.Short }

    // Begin constructing our encrypted string
    let encrypted = password + str + password
    return String(encrypted.characters.reverse())
}

New terms and important words are shown in bold. Words that you see on the screen, for example, in menus or dialog boxes, appear in the text like this: "To run the app, select the GuessingGame WatchKit App scheme as shown in the following screenshot and then select your preferred device."

Note

Warnings or important notes appear in a box like this.

Tip

Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or disliked. Reader feedback is important for us as it helps us develop titles that you will really get the most out of.

To send us general feedback, simply e-mail , and mention the book's title in the subject of your message.

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide at www.packtpub.com/authors.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the example code

You can download the example code files for this book from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

You can download the code files by following these steps:

  1. Log in or register to our website using your e-mail address and password.

  2. Hover the mouse pointer on the SUPPORT tab at the top.

  3. Click on Code Downloads & Errata.

  4. Enter the name of the book in the Search box.

  5. Select the book for which you're looking to download the code files.

  6. Choose from the drop-down menu where you purchased this book from.

  7. Click on Code Download.

You can also download the code files by clicking on the Code Files button on the book's webpage at the Packt Publishing website. This page can be accessed by entering the book's name in the Search box. Please note that you need to be logged in to your Packt account.

Once the file is downloaded, please make sure that you unzip or extract the folder using the latest version of:

  • WinRAR / 7-Zip for Windows

  • Zipeg / iZip / UnRarX for Mac

  • 7-Zip / PeaZip for Linux

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you could report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded to our website or added to any list of existing errata under the Errata section of that title.

To view the previously submitted errata, go to https://www.packtpub.com/books/content/support and enter the name of the book in the search field. The required information will appear under the Errata section.

Piracy

Piracy of copyrighted material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works in any form on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at with a link to the suspected pirated material.

We appreciate your help in protecting our authors and our ability to bring you valuable content.

Questions

If you have a problem with any aspect of this book, you can contact us at , and we will do our best to address the problem.