12
Apple Watch Kit HoangNA - CuongNT Team iOS - RikkeiSoft Ltd 05-2015

Apple Watch Kit trainning slide [team iOS - RikkeiSoft]

Embed Size (px)

Citation preview

Apple Watch Kit

HoangNA - CuongNT

Team iOS - RikkeiSoft Ltd

05-2015

Introduction

- Watch Kit was introduced in November 2014.- Apple Watch is just an external display for program running on a connected iPhone.- Watch Kit development requires the iOS 8.2 SDK or later.- Two separate bundles:+ WatchKit app (runs on Apple Watch)+ WatchKit extension (runs on user’s iPhone)

Watch Kit SolutionHas 3 projects:

- The Watch Extension: runs on the connected iPhones, contains the code and large resource storage for the Watch App but has no visible representation beyond what the Watch App provides.

- The Watch App: small project which runs on the Apple Watch, generally consisting of only a storyboard, small resources, and link references to files in the Watch Extension.

- The iOS Parent App: a project whose primary purpose is to bundle the Watch App and Extension.

Application Lifecycle (1)

- Handle each Storyboard scene by a subclass of WKInterfaceController.

- WKInterfaceController ≈ UIViewController (do not have the same level of access to the view components).

- Can: + hide and reveal controls + change size, transparency, appearance options of some controls

- Can’t: + dynamically add controls + restructure UI

Application Lifecycle (2)The lifecycle of a WKInterfaceController object involves the following calls:

• Awake: should perform most of initialization here.

• WillActive: Call shortly before the Watch App appears. Use this method to perform last-moment initialization, start animation, etc.

• At this point, the Watch App appears and the Extension begins responding to user input and updating the Watch App’s display per application logic.

• DidDeactivate: is called after the Watch App has been dismissed by the user or the connection to the iPhone is broken. After this method returns, user interface controls can’t be modified until the next time WillActive is called.

• After the Extension has been deactivated, it is inaccessible to program. Pending asynchronous functions will not be called.

Types of User Interface

• Normal Interaction: the majority of Watch App/Extension interaction will be with sub-class of WKInterfaceController (by custom controllers: LabelDetailController, ButtonDetailController, SwitchDetailController, etc.)

• Glances: non-interactive, single-page UIs that are intended to provide summary or crucial data.

• Notifications: are a major user-case for the Apple Watch. Both local and remote notifications are supported.

User Interface: Normal Interaction

User Interface: Glances

When a Glance is tapped, it launches the main Watch App. Glances may deep-link into the Watch App by passing context info in a call to WKInterfaceController.UpdateUserActivity.

User Interface: Notifications

- Occurs in two stages: Short Locks and Long Lock

• Short Locks: displayed briefly and show the Watch App icon, its name and the Title.

• Long Lock: combines a system provided sash area and Dismiss button with custom Storyboard-based content.

- React to notification event by overriding two methods DidReceiveLocalNotification and DidReceiveRemoteNotification

Screen SizesThe Apple Watch has two face sizes: 38mm & 42mm, both are 5:4 display ratio,

Retina screen.

• 38mm: 136 x 170 logical pixels ( 272 x 340 physical pixels)

• 42mm: 156 x 195 logical pixels (312 x 390 physical pixels)

Use WKInterfaceDevice.ScreenBounds to determine on which display Watch App is

running.

(*): Should develop text and layout design with 38mm display then scale up because

scaling down from large environment may lead to ugly overlap or text truncation.

Limit of Watch Kit• No access to the sensors on the Apple Watch.

• The App/Extension will not run without an active connection to an iPhone.

Notifications will not appear on a disconnected Watch.

• The Watch App has a 20Mb image cache

(WKInterfaceDevice.CurrentDevice.AddCachedImage,

WKInterfaceDevice.CurrentDevice.WeakCachedImages). This limit can’t be

changed and developers must manage the cache contents themselves.

• Different classes ( WKInterfaceButton vs UIButton, WKInterfaceSwitch vs

UISwitch, etc) and have a limited set of methods compared to their UIKit

equivalents.

• No access to the display graphic context on the Watch.

• Apple will not allow 3rd-party custom watch faces.

• Doesn’t support background execution. Any pending asynchronous functions will

not execute after Watch Kit Extensions are being deactivated.

• Can’t play sound on the Apple Watch.

• No access to the Taptic (Vibration) API.

• Cannot route notifications to the Watch only or the iPhone only.

References

• https://developer.apple.com/library/prerelease/ios/documentation/General/Conce

ptual/WatchKitProgrammingGuide/index.html

• https://developer.apple.com/watch/human-interface-guidelines/

• http://www.raywenderlich.com/89562/watchkit-tutorial-with-swift-getting-started

• http://developer.xamarin.com/guides/ios/watch/intro-to-watchkit/