Chapter 10. Apple Watch

The latest version of watchOS gives us developers a lot more control and brings cool features to the users as well. Now that we can download files directly and get access to sensors directly on the watch, the users will benefit.

In this chapter, I am going to assume that you have a simple iOS application in Xcode already created and you want to add a watchOS 3 target to your app. So, go to Xcode and create a new target. In the new window, choose Watch OS on the lefthand side and select WatchKit App on the right (see Figure 10-1). Then click Next.

Figure 10-1. Adding a WatchKit App target to your main application

On the next screen, make sure that you have enabled complications (we’ll talk about this later) and the glance scene (see Figure 10-2).

Figure 10-2. Add a complication and a glance scene to your watch app

After you have created your watch extension, you want to be able to run it on the simulator. To do this, simply choose your app from the targets in Xcode and click the Run button.

10.1 Downloading Files onto the Apple Watch

Problem

You want to be able to download files from your watch app directly without needing to communicate your intentions to the paired iOS device.

Solution

Use URLSession as you would on a phone, but with more consideration ...

Get iOS 11 Swift Programming Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.