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

Download Apple Watch Docs - Read the Docs Apple Watch Docs, Release 0.1 By Michael Hahn, May 2015 The Apple Watch

Post on 26-May-2020

0 views

Category:

Documents

0 download

Embed Size (px)

TRANSCRIPT

  • Apple Watch Docs Release 0.1

    Michael Hahn

    Nov 20, 2017

  • Contents

    1 First Watch ‘Glance’ 3 1.1 Create an iPhone App . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 1.2 Add WatchKit Targets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 1.3 Add Glance Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 1.4 Verify Operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 1.5 Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7

    2 First Watch Notification 9 2.1 Create an iPhone App . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 2.2 Add WatchKit Targets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 2.3 Add Watch Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 2.4 Verify Operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13

    3 Contact Us 15

    4 Indices and tables 17

    i

  • ii

  • 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 the smart watch is no exception. If you are new to smart watches you first need to learn about the Apple WatchKit and become familiar with the SDK and tools that make it all possible. This site helps developers quickly work through the basic concepts and create their first Apple Watch extension. If you are also interested in developing wearable applications for Android, see http://androidweardocs.com.

    Contents:

    Contents 1

    http://androidweardocs.com

  • Apple Watch Docs, Release 0.1

    2 Contents

  • 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 information about a task at hand, like an upcoming meeting or workout status. The only user input is a screen tap, which launches the WatchKit app. From the developer perspective, launching the WatchKit app from a glance is a way to customize the 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 in Xcode.

    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 options window 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 of the new project.

    3

  • Apple Watch Docs, Release 0.1

    4 Chapter 1. First Watch ‘Glance’

  • 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 an existing 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 the remaining 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

  • 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 button to change the hello message.

    1. In the Navigator, expand the Glance WatchKit App folder and click the Interface.storyboard. Locate and select the 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 an image 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 beginning until an Insert Outlet appears. Stop there and a dialog opens where you can set the connection as an outlet and enter 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 text label.setText("Hello World") super.willActivate()

    }

    6 Chapter 1. First Watch ‘Glance’

  • 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 instead of the Main Interface. You cannot view Glance messages in the Main Interface. Xcode makes the necessary glance Scheme for you when it creates the WatchKit target. To use it, select the dropdown near the run/stop icons and choose Glance - Glance Watchkit App. If you are interested in viewing the actual setting, edit this scheme, select run, and view the Watch Interface setting.

    In Xcode, start the emulator and view the watch. If necessary, select Apple Watch as the External Display under the Hardware 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

    https://github.com/LarkspurCA/applewatchglance

  • Apple Watch Docs, Release 0.1

    8 Chapter 1. First Watch ‘Glance’

  • 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 timely information, such as incoming messages or upcoming appointments. It can also display useful information about a task at hand, such as workout status or recipe preparation. The watch initially displays a summary of the notification in the Short Look format, then advances to a Long Look if the user continues to view the notification. The Long Look is a scrollable display that includes notification details and Action Buttons. This section explains how to create your first 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 in Xcode.

    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 options window is displayed.

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

    • Product Name

    • Organization Name

    • Language

    9

  • Apple Watch Docs, Release 0.1

    10 Chapter 2. First Watch Notification

  • 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 the new 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 an existing 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

  • 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 button to change the hello message.

    1. In the Navigator, expand the hello WatchKit App folder and click the Interface.storyboard. Locate and select the 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 the beginning until an Insert Outlet appears. Stop there and a dialog opens where you can set the connection as an outlet and enter the name. Xcode then adds an IBOutlet variable for the label to the code