Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Native watch apps and third-party complications

Native watch apps and third-party complications

Let's take a practical look at Apple's newest development platform watchOS, by implementing a GitHub streak custom complication and a native Spotify watch app.

Boris Bügling

July 20, 2015
Tweet

More Decks by Boris Bügling

Other Decks in Programming

Transcript

  1. !!!

  2. EXTENSION DELEGATE class ExtensionDelegate: NSObject, WKExtensionDelegate { func applicationDidFinishLaunching() {

    } func applicationDidBecomeActive() { } func applicationWillResignActive() { } }
  3. INTERFACE CONTROLLER class InterfaceController: WKInterfaceController { override func awakeWithContext(context: AnyObject?)

    { super.awakeWithContext(context) } override func willActivate() { super.willActivate() } override func didDeactivate() { super.didDeactivate() } }
  4. CLKCOMPLICATIONFAMILY enum CLKComplicationFamily : Int { case ModularSmall case ModularLarge

    case UtilitarianSmall case UtilitarianLarge case CircularSmall }
  5. CLKCOMPLICATIONTEMPLATE The CLKComplicationTemplate class is a base class for specifying

    the arrangement of data in your custom watch complication.
  6. ...

  7. If you measure interactions with your iOS app in minutes,

    you can expect interactions with your Watch app to be measured in seconds.
  8. LAYOUT ▸ based on horizontal or vertical groups ▸ very

    similar to UIStackView ▸ two device sizes (38mm and 42mm) ▸ edge-to-edge, bezel provides margins
  9. WATCHPRESENTER ▸ Remote controls Deckset instead ▸ Direct connection to

    the Mac ▸ Shows a preview of the slides ▸ Measures heartrate to display the "most exciting" slide ▸ Taps you if you're running out of time
  10. HEALTHKIT.FRAMEWORK let anchorValue = Int(HKAnchoredObjectQueryNoAnchor) let sampleType = HKObjectType.quantityTypeForIdentifier(HKQuantityTypeIdentifierHeartRate) let

    heartRateQuery = HKAnchoredObjectQuery(type: sampleType!, predicate: nil, anchor: anchorValue, limit: 0) { (query, sampleObjects, deletedObjects, newAnchor, error) -> Void in guard let heartRateSamples = sampleObjects as?[HKQuantitySample] else {return} let sample = heartRateSamples.first let value = sample!.quantity.doubleValueForUnit(self.heartRateUnit) print(value) } heartRateQuery.updateHandler = // ...
  11. TAPTIC ENGINE typedef NS_ENUM(NSInteger, WKHapticType) { WKHapticTypeNotification, WKHapticTypeDirectionUp, WKHapticTypeDirectionDown, WKHapticTypeSuccess,

    WKHapticTypeFailure, WKHapticTypeRetry, WKHapticTypeStart, WKHapticTypeStop, WKHapticTypeClick } WK_AVAILABLE_WATCHOS_ONLY(2.0); WKInterfaceDevice.currentDevice().playHaptic(.Start)
  12. WHAT HAVE WE LEARNED? ▸ Code isn't very different from

    iOS apps ▸ But design very much is ▸ Rethink your app for the watch, don't port it ▸ If you can't - maybe you don't need a watch app