iosswiftwatchkitapple-watchwatchos-4

How to put the Digital Crown back to work with watchOS 4


I've got a watchkit app that makes use of the digital crown by setting

crownSequencer.delegate = self
crownSequencer.focus()

In the awake method of my interface controller that's implementing:

class InterfaceController: WKInterfaceController, WKCrownDelegate 

In watchOS 3 my delegate Method was executed just fine:

// called when the crown rotates, rotationalDelta is the change since the last call (sign indicates direction).
func crownDidRotate(_ crownSequencer: WKCrownSequencer?, rotationalDelta: Double) {

    // do something important here...
}

After upgrading to watchos4, this functionality breaks. A simple recompile and conversion to swift 4 didn't help.


Solution

  • I could solve this problem by simply moving the crownSequencer code to the willActivate method of my interface controller:

    override func willActivate() {
        ...
    
        crownSequencer.delegate = self
        crownSequencer.focus()
    }
    

    It looks to me that something steals the focus in watchOS 4 (maybe something related to the spritekit I'm using?) if you set the focus too early.

    Hope this saves some time for someone else!