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

767 Views Asked by At

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.

2

There are 2 best solutions below

2
On BEST ANSWER

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!

0
On

I was unable to solve it that simply. I needed to add a delay to reestablish focus on the crown as follows:

-(void)delayDo{

self.crownSequencer.delegate=self;

[self.crownSequencer focus];

}

-(void)didAppear{

[self performSelector:@selector(delayDo) withObject:nil afterDelay:1.0f];

}