I'm trying to print crown input in Apple Watch and I can't get it to work.
I have created a new watch app (for watch only).
I have this in my HostingController:
import WatchKit
import Foundation
import SwiftUI
class HostingController: WKHostingController<ContentView>, WKCrownDelegate {
override func awake(withContext context: Any?) {
super.awake(withContext: context)
print("awake")
crownSequencer.delegate = self
}
override func willActivate() {
super.willActivate()
print("willActivate")
crownSequencer.focus()
}
func crownDidRotate(_ crownSequencer: WKCrownSequencer?, rotationalDelta: Double) {
print("\(rotationalDelta)")
}
override var body: ContentView {
return ContentView()
}
}
In the console "awake" and "willActivate" are both showing up. But when I am rotating the crown nothing shows up.
What am I missing?
OK after a lot of digging and testing I solved this.
The crown will register movements in WKInterfaceController class extension and not in WKHostingController that I was referring to in my question.
I am very new to watch development so I can't figure out why is this happening, but it works.