apple watch docs - read the docs · apple watch docs, release 0.1 by michael hahn, may 2015 the...

21
Apple Watch Docs Release 0.1 Michael Hahn Nov 20, 2017

Upload: others

Post on 26-May-2020

12 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Apple Watch Docs - Read the Docs · Apple Watch Docs, Release 0.1 By Michael Hahn, May 2015 The Apple Watch us an exciting new entry into the wearable market. Apple has a long history

Apple Watch DocsRelease 0.1

Michael Hahn

Nov 20, 2017

Page 2: Apple Watch Docs - Read the Docs · Apple Watch Docs, Release 0.1 By Michael Hahn, May 2015 The Apple Watch us an exciting new entry into the wearable market. Apple has a long history
Page 3: Apple Watch Docs - Read the Docs · Apple Watch Docs, Release 0.1 By Michael Hahn, May 2015 The Apple Watch us an exciting new entry into the wearable market. Apple has a long history

Contents

1 First Watch ‘Glance’ 31.1 Create an iPhone App . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31.2 Add WatchKit Targets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51.3 Add Glance Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61.4 Verify Operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71.5 Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7

2 First Watch Notification 92.1 Create an iPhone App . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92.2 Add WatchKit Targets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112.3 Add Watch Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122.4 Verify Operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13

3 Contact Us 15

4 Indices and tables 17

i

Page 4: Apple Watch Docs - Read the Docs · Apple Watch Docs, Release 0.1 By Michael Hahn, May 2015 The Apple Watch us an exciting new entry into the wearable market. Apple has a long history

ii

Page 5: Apple Watch Docs - Read the Docs · Apple Watch Docs, Release 0.1 By Michael Hahn, May 2015 The Apple Watch us an exciting new entry into the wearable market. Apple has a long history

Apple Watch Docs, Release 0.1

By Michael Hahn, May 2015

The Apple Watch us an exciting new entry into the wearable market. Apple has a long history of innovation and thesmart watch is no exception. If you are new to smart watches you first need to learn about the Apple WatchKit andbecome familiar with the SDK and tools that make it all possible. This site helps developers quickly work throughthe basic concepts and create their first Apple Watch extension. If you are also interested in developing wearableapplications for Android, see http://androidweardocs.com.

Contents:

Contents 1

Page 6: Apple Watch Docs - Read the Docs · Apple Watch Docs, Release 0.1 By Michael Hahn, May 2015 The Apple Watch us an exciting new entry into the wearable market. Apple has a long history

Apple Watch Docs, Release 0.1

2 Contents

Page 7: Apple Watch Docs - Read the Docs · Apple Watch Docs, Release 0.1 By Michael Hahn, May 2015 The Apple Watch us an exciting new entry into the wearable market. Apple has a long history

CHAPTER 1

First Watch ‘Glance’

By Michael Hahn, May 2015

The Glance context is one of the core functions for the Apple Watch. It provides a simple display of timely informationabout a task at hand, like an upcoming meeting or workout status. The only user input is a screen tap, which launchesthe WatchKit app. From the developer perspective, launching the WatchKit app from a glance is a way to customizethe launch behavior. This section describes how to display a simple message using a Glance.

1.1 Create an iPhone App

Apple Watch applications always start with an app on the Phone. For this procedure, create a new empty phone app inXcode.

1. Open Xcode. The Welcome to Xcode window is displayed.

2. Select Create a new Xcode project. The template choices are displayed.

3. Select iOS and Application, and then choose Single View Application. Click Continue. The target optionswindow is displayed.

4. Enter the project options for your project. As a minimum set the following properties.

• Product Name: Glance

• Organization Name: Apple Watch Docs

• Language: Swift

5. Choose a location in your file system for your project and click Create. Xcode opens to the Glance target ofthe new project.

3

Page 8: Apple Watch Docs - Read the Docs · Apple Watch Docs, Release 0.1 By Michael Hahn, May 2015 The Apple Watch us an exciting new entry into the wearable market. Apple has a long history

Apple Watch Docs, Release 0.1

4 Chapter 1. First Watch ‘Glance’

Page 9: Apple Watch Docs - Read the Docs · Apple Watch Docs, Release 0.1 By Michael Hahn, May 2015 The Apple Watch us an exciting new entry into the wearable market. Apple has a long history

Apple Watch Docs, Release 0.1

1.2 Add WatchKit Targets

Apple implements a watch app as two new targets, a WatchKit Extender and a WatchKit App. You add these to anexisting iPhone app using Xcode.

1. In Xcode, select File -> New -> Target.

2. Select Apple Watch under iOS, choose WatchKit, and Click Continue. The target options window is dis-played.

3. Select Include Glance Scene. For simplicity, unselect Include Notification Scene. Accept defaults for theremaining options and click Continue.

4. If prompted to activate a theme, click Activate. Xcode opens to the Hello WatchKit App target.

1.2. Add WatchKit Targets 5

Page 10: Apple Watch Docs - Read the Docs · Apple Watch Docs, Release 0.1 By Michael Hahn, May 2015 The Apple Watch us an exciting new entry into the wearable market. Apple has a long history

Apple Watch Docs, Release 0.1

1.3 Add Glance Code

The default watch app only displays the time, so this example adds a text field to hold the Hello message and a buttonto change the hello message.

1. In the Navigator, expand the Glance WatchKit App folder and click the Interface.storyboard. Locate and selectthe Glance interface graphic. This is where you build the Glance UI.

2. From the Object Library, drag a Label to the upper group in the glance interface graphic. Optionally, drag animage object to the lower group in the graphic and initialize it with a local image.

3. Add an IBOutlet for the label to the glanceController. Visually, display both the storyboard and interfaceCon-troller. Control -> click the label and drag to the glanceController code, positioning the cursor near the beginninguntil an Insert Outlet appears. Stop there and a dialog opens where you can set the connection as an outlet andenter the name. Xcode then adds an IBOutlet variable for the label to the code.

class GlanceController: WKInterfaceController {@IBOutlet weak var label: WKInterfaceLabel!

...

4. Modify the willActivate method to change the label to Hello World when the app starts.

override func willActivate() {// Set the label textlabel.setText("Hello World")super.willActivate()

}

6 Chapter 1. First Watch ‘Glance’

Page 11: Apple Watch Docs - Read the Docs · Apple Watch Docs, Release 0.1 By Michael Hahn, May 2015 The Apple Watch us an exciting new entry into the wearable market. Apple has a long history

Apple Watch Docs, Release 0.1

1.4 Verify Operation

If you are using the emulator, you must change the emulation Scheme to display the Glance Watch Interface insteadof the Main Interface. You cannot view Glance messages in the Main Interface. Xcode makes the necessary glanceScheme for you when it creates the WatchKit target. To use it, select the dropdown near the run/stop icons and chooseGlance - Glance Watchkit App. If you are interested in viewing the actual setting, edit this scheme, select run, andview the Watch Interface setting.

In Xcode, start the emulator and view the watch. If necessary, select Apple Watch as the External Display under theHardware menu. When you click the button the Hello World text is displayed in the label.

1.5 Example

For the sample Xcode project, see https://github.com/LarkspurCA/applewatchglance.

1.4. Verify Operation 7

Page 12: Apple Watch Docs - Read the Docs · Apple Watch Docs, Release 0.1 By Michael Hahn, May 2015 The Apple Watch us an exciting new entry into the wearable market. Apple has a long history

Apple Watch Docs, Release 0.1

8 Chapter 1. First Watch ‘Glance’

Page 13: Apple Watch Docs - Read the Docs · Apple Watch Docs, Release 0.1 By Michael Hahn, May 2015 The Apple Watch us an exciting new entry into the wearable market. Apple has a long history

CHAPTER 2

First Watch Notification

By Michael Hahn, May 2015

The notification context stream is one of the core functions for the Apple Watch. It consists of a message about timelyinformation, such as incoming messages or upcoming appointments. It can also display useful information about atask at hand, such as workout status or recipe preparation. The watch initially displays a summary of the notificationin the Short Look format, then advances to a Long Look if the user continues to view the notification. The Long Lookis a scrollable display that includes notification details and Action Buttons. This section explains how to create yourfirst watch notification.

2.1 Create an iPhone App

Apple Watch applications always start with an app on the Phone. For this procedure, create a new empty phone app inXcode.

1. Open Xcode. The Welcome to Xcode window is displayed.

2. Select Create a new Xcode project. The template choices are displayed.

3. Select iOS and Application, and then choose Single View Application. Click Continue. The target optionswindow is displayed.

4. Enter the project options for your project, and then click Next. As a minimum set the following values. Thescreen capture shows the values for the hello example app.

• Product Name

• Organization Name

• Language

9

Page 14: Apple Watch Docs - Read the Docs · Apple Watch Docs, Release 0.1 By Michael Hahn, May 2015 The Apple Watch us an exciting new entry into the wearable market. Apple has a long history

Apple Watch Docs, Release 0.1

10 Chapter 2. First Watch Notification

Page 15: Apple Watch Docs - Read the Docs · Apple Watch Docs, Release 0.1 By Michael Hahn, May 2015 The Apple Watch us an exciting new entry into the wearable market. Apple has a long history

Apple Watch Docs, Release 0.1

5. Choose a location in your file system for your project and click Create. Xcode opens to the hello target of thenew project.

2.2 Add WatchKit Targets

Apple implements a watch app as two new targets, a WatchKit Extender and a WatchKit App. You add these to anexisting iPhone app using Xcode.

1. In Xcode, select File -> New -> Target.

2. Select Apple Watch under iOS, choose WatchKit, and Click Continue. The target options window is dis-played.

3. Accept the default options and click Finish.

4. If prompted to activate a theme, click Activate. Xcode opens to the Hello WatchKit App target.

2.2. Add WatchKit Targets 11

Page 16: Apple Watch Docs - Read the Docs · Apple Watch Docs, Release 0.1 By Michael Hahn, May 2015 The Apple Watch us an exciting new entry into the wearable market. Apple has a long history

Apple Watch Docs, Release 0.1

2.3 Add Watch Code

The default watch app only displays the time, so this example adds a text field to hold the Hello message and a buttonto change the hello message.

1. In the Navigator, expand the hello WatchKit App folder and click the Interface.storyboard. Locate and selectthe Interface graphic. This is where you build the watch app UI.

2. From the Object Library, drag a Label and a Button to the watch face.

3. Add an IBOutlet for the label to the interfaceController. Visually, display both the storyboard and interface-Controller. Control -> click the label and drag to the InterfaceController code, positioning the cursor near thebeginning until an Insert Outlet appears. Stop there and a dialog opens where you can set the connection as anoutlet and enter the name. Xcode then adds an IBOutlet variable for the label to the code.

class InterfaceController: WKInterfaceController {

@IBOutlet weak var label: WKInterfaceLabel!

4. Similarily, add an action to the button. In the case of an action however, when the dialog opens choose actionas the connection type and enter the name of the method that implements the action. Xcode adds an IBActionmethod.

@IBAction func didClick() {}

5. Implement the didClick method. This simple example updates the label text with the hello message.

var clickNumber = 0

12 Chapter 2. First Watch Notification

Page 17: Apple Watch Docs - Read the Docs · Apple Watch Docs, Release 0.1 By Michael Hahn, May 2015 The Apple Watch us an exciting new entry into the wearable market. Apple has a long history

Apple Watch Docs, Release 0.1

@IBAction func didClick() {var myString = "Hello World " + String(clickNumber++)label.setText(myString)

}

2.4 Verify Operation

In Xcode, start the emulator and view the watch. If necessary, select Apple Watch as the External Display under theHardware menu. When you click the button the Hello World text is displayed in the label, followed by the number oftimes you clicked the button.

2.4. Verify Operation 13

Page 18: Apple Watch Docs - Read the Docs · Apple Watch Docs, Release 0.1 By Michael Hahn, May 2015 The Apple Watch us an exciting new entry into the wearable market. Apple has a long history

Apple Watch Docs, Release 0.1

14 Chapter 2. First Watch Notification

Page 19: Apple Watch Docs - Read the Docs · Apple Watch Docs, Release 0.1 By Michael Hahn, May 2015 The Apple Watch us an exciting new entry into the wearable market. Apple has a long history

CHAPTER 3

Contact Us

Apple Watch Docs

[email protected]

15

Page 20: Apple Watch Docs - Read the Docs · Apple Watch Docs, Release 0.1 By Michael Hahn, May 2015 The Apple Watch us an exciting new entry into the wearable market. Apple has a long history

Apple Watch Docs, Release 0.1

16 Chapter 3. Contact Us

Page 21: Apple Watch Docs - Read the Docs · Apple Watch Docs, Release 0.1 By Michael Hahn, May 2015 The Apple Watch us an exciting new entry into the wearable market. Apple has a long history

CHAPTER 4

Indices and tables

• genindex

• search

17