$30 off During Our Annual Pro Sale. View Details »

Practical WatchKit Development (UIKonf 2015)

Practical WatchKit Development (UIKonf 2015)

Presentation at UIKonf 2015 in Berlin http://www.uikonf.com

Claus Höfele

May 18, 2015
Tweet

More Decks by Claus Höfele

Other Decks in Programming

Transcript

  1. Practical WatchKit
    Development
    @claushoefele

    View Slide

  2. Kleinanzeigen TransitHopper

    View Slide

  3. WatchKit
    App
    WatchKit
    Extension
    iOS App
    WatchKit App vs Extension

    View Slide

  4. View Slide

  5. Interactive Notifications

    View Slide

  6. class TripDetailInterfaceController: WKInterfaceController {
    @IBOutlet private weak var map: WKInterfaceMap!
    override func awakeWithContext(context: AnyObject?) {
    super.awakeWithContext(context)
    ...
    }
    override func willActivate() {
    super.willActivate()
    ...
    }
    }

    View Slide

  7. map.addAnnotation(coordinate, withPinColor: .Red)
    let coordinateRegion =
    MKCoordinateRegionMakeWithDistance[...]
    map.setRegion(coordinateRegion)

    View Slide

  8. Tables

    View Slide

  9. Paging

    View Slide

  10. Hides when loading
    Off On

    View Slide

  11. View Slide

  12. WatchKit
    App
    WatchKit
    Extension
    Requesting Data

    View Slide

  13. WatchKit
    App
    WatchKit
    Extension
    iOS App
    openParentApplication()

    View Slide

  14. private func callParentApp() {
    let userInfo = ["input": "data"]
    WKInterfaceController.openParentApplication(userInfo) { replyInfo, error in
    println("reply \(replyInfo)")
    }
    }
    func application(_:handleWatchKitExtensionRequest:reply:)
    Calling the Parent App

    View Slide

  15. Handoff

    View Slide

  16. User Location Permissions
    WatchKit
    App
    WatchKit
    Extension
    iOS App
    When In Use
    Always

    View Slide

  17. WatchKit
    Extension
    iOS App
    Sharing
    Data

    View Slide

  18. View Slide

  19. let defaults = NSUserDefaults(suiteName: "group.com.claushoefele.T")!
    func updateObjectForKey(key: String, item: T) {
    let data = NSKeyedArchiver.archivedDataWithRootObject(item)
    defaults.setObject(data, forKey: key)
    }

    View Slide

  20. WatchKit
    Extension
    iOS App
    Signalling

    View Slide

  21. func sendDarwinNotification(identifier: String) {
    let darwinNotificationCenter = CFNotificationCenterGetDarwinNotifyCenter()
    CFNotificationCenterPostNotification(darwinNotificationCenter,
    identifier, nil, nil, 1);
    }
    CFNotificationCenterAddObserver

    View Slide

  22. Data Sync

    View Slide

  23. “A WatchKit app
    complements your iOS app;
    it does not replace it.”
    –Apple Watch HIG

    View Slide

  24. “Anything that could show
    the user a progress
    spinner (however briefly)
    is a failure on my part.”
    –David Smith

    View Slide

  25. “[…] many of us — 
    developers included — are
    still figuring out how this
    device fits into daily life […]”
    –M.G. Siegler

    View Slide

  26. Practical WatchKit
    Development
    @claushoefele
    http://slack.fiveminutewatchkit.com

    View Slide