Getting Started with Apple WatchKit and WatchOS 2

Continued from page 2. 

Similar to iOS--which uses CoreMotion to leverage the accelerometer, gyroscope and megnetometer to create coordinates in a data structure called device motion--developers can track and aggregate a user's wrists, the speed the watch is moving in, and its vertical pointing position (relative to the horizon or heading relative to to true (or magnetic north). To track motion, you would use CMMotionManager class, as you would on iOS, receiving acceleration values in the form of x,y,z, which allows you to determine the speed, heading and position of the watch relative to the horizon.

Getting Started with Taptic Engine

Taptic Engine provides the vibrating feedback users recieve when they, for example,  are getting directions when navigating with their watch, or notifications when an email or text arrives. Each type of notification is distinct, whether it’s a singular vibration or multiple vibrations.

Using the WKHapticType enumerator, developers are able to sepect from a predefined range of haptic types:

  • WKHapticTypeNotification,
  • WKHapticTypeDirectionUp,
  • WKHapticTypeDirectionDown,
  • WKHapticTypeSuccess,
  • WKHapticTypeFailure,
  • WKHapticTypeRetry,
  • WKHapticTypeStart,
  • WKHapticTypeStop,
    • WKHapticTypeClick

Apple is pressing developers to stick to the current set of vibration types, and to implement them responsibly and consistently.

Digital Crown

The Digital Crown is one of the most prominent hardware features of the Apple Watch, providing the timeliness watch, whilst providing the digital functionality to be able to scroll through UI elements.

There is no direct API for adding Digital Crown in a custom way, but through the various other UI elements, such as WKInterfacePicker which we mentioned earlier in this article, you are able to obtain delegate callbacks when the user scrolls using the Digital Crown. For the picker, this includes the ability to control the picker focus (highlighted item) and resign focus.

Heart Rate Information

Finally, developers can access heart-rate information directly from the watch device, rather than indirectly through HealthKit. The distinction is, developers now have access to live heart rate data as opposed to data after-the fact. App vendors like RunKeeper and Nike+ can access live heart-rate data now and aggregate the information as the users are exercising.

Watch Complications

Apple has finally given developers the ability to create custom *Watch Complications, elements that appear on the watch face for frequent ticker-style or widget visuals. Some of the already established Apple complications include weather information, calendar events and world clock. Adding custom complications, developers can add fancy ticker items such as flight/gate information or any other sort of app-specific data.

image

Within the Watch Face, complications are modular and size-generic, with the placement determined by watchOS and based on the existing face layout. The layout above has space for five different complications, in two different sizes.

Implementing complications is done through the ClockKit Framework and consists of various complication families:

image

Depending on the complication family, developers can choose what kind of data can be displayed using a ClockKit template, with each template providing a different arrangement of text, images or combination of both. ClockKit renders the data within the template constraints, during runtime.

The Watch Complications are even more dynamic with the help of the Digital Crown, allowing users to see into the future, so to speak. Take the calendar complication: By turning the Digital Crown, users can see calendar events scheduled into the future, as well as in the past.

The past, present, and future entries returned by your data source object are used to build a timeline of your complication’s data. Each timeline entry consists of an NSDate object and a complication template with the data that you want to display. When the specified date and time arrives, ClockKit renders the data from the corresponding template into the space occupied by your complication. As time passes, ClockKit updates your complication based on the entries in your timeline. (source: Apple)

Complications are also rendered in advance to ensure no lag, delay or over-use of power. Thus, developers need to provide as much data as available to be cached.

!image](https://developer.apple.com/library/prerelease/watchos/documentation/Gen...)

ClockKit is a huge topic in itself, and certainly worth exploring more. We will cover ClockKit in a separate article in the future.

Conculsion

Developers are no doubt excited by what watchOS 2 has exposed for them--from native apps through connectivity, from new and extensive hardware accessibility to accelerometer, Taptic Engine feedback  and Digital Crown feedback. The new architecture allows apps to be more responsive and autonomous, as watch apps will not only run natively but will also acquire network data from the cloud directly. This is certainly a performance win for developers. Further, Apple will no doubt lean heavily on its army of developers to come up with new and exciting apps, thanks to watchOS 2.

Further Reading

Be sure to read the next Mobile article: Code Sign Your Apps on iOS with Less Fuss and Muss

 

Comments (0)