Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WKCrownDelegate doesn't seem to be working with Xcode 9 GM

Tags:

xcode

watchos

I've tried the code below targeting both iOS 10.0/Watch OS 3.0 and iOS 11.0/Watch OS 4.0, and tested both in the simulator and my Watch OS 4 device. Nothing seems to trigger the crownDidRotate delegate method.

Simple interface with one label connected to the outlet. I know it's connected because I change the text in the awake method. Breaking in the delegate method never stops when I rotate the crown.

Any ideas?

import Foundation
import WatchKit
class InterfaceController: WKInterfaceController, WKCrownDelegate {
    var value = 1
    @IBOutlet var label: WKInterfaceLabel!
    override func awake(withContext context: Any?) {
        super.awake(withContext: context)
        label.setText("Yeah?")
        crownSequencer.delegate = self
        crownSequencer.focus()
    }
    func crownDidRotate(_ crownSequencer: WKCrownSequencer?, rotationalDelta: Double) {
        label.setText("Rotational: \(rotationalDelta)")
    }
}
like image 439
Matt H Avatar asked Sep 16 '17 01:09

Matt H


2 Answers

I had the same experience. As a hack, I added another call to crownSequencer.focus() in willActivate(), and I'm now seeing events. (xcode 9.0 gm, ios 11.0 gm, watchos 4.0 gm)

like image 132
Larry Drebes Avatar answered Nov 12 '22 08:11

Larry Drebes


Adding crownSequencer.focus() in willActivate() did not help me in Xcode10. You don't have to call crownSequencer.focus() neither in awake() or in willActivate() but in didAppear(). So you need to add the following lines:

override func didAppear() {
    super.didAppear()
    crownSequencer.focus()
}
like image 24
Gergely Avatar answered Nov 12 '22 06:11

Gergely