watchOS 3 adds WKCrownSequencer
and WKCrownDelegate
to report the state of the digital crown (such as rotational speed), as well as to receive notifications when the user rotates the crown.
You can use the crown sequencer to provide general input to control scenes or interface objects.
Apple has updated their WatchKit Catalog sample code to include a WKInterfaceController crown sequencer example demonstrating how to use the Apple Watch digital crown to interact with other objects:
class CrownDetailController: WKInterfaceController, WKCrownDelegate {
@IBOutlet var velocityLabel: WKInterfaceLabel!
@IBOutlet var stateLabel: WKInterfaceLabel!
@IBOutlet var pickerView: WKInterfacePicker!
override func awake(withContext context: AnyObject?) {
super.awake(withContext: context)
let itemList: [(String, String)] = [
("Item 1", "Red"),
("Item 2", "Green"),
("Item 3", "Blue")
]
let pickerItems: [WKPickerItem] = itemList.map {
let pickerItem = WKPickerItem()
pickerItem.caption = $0.0
pickerItem.title = $0.1
return pickerItem
}
pickerView.setItems(pickerItems)
crownSequencer.delegate = self
}
override func willActivate() {
// This method is called when watch view controller is about to be visible to user
super.willActivate()
crownSequencer.focus()
}
@IBAction func focusCrown(sender: AnyObject) {
crownSequencer.focus()
}
func updateCrownLabels() {
velocityLabel.setText(String(format: "RPS: %2.2lf", crownSequencer.rotationsPerSecond))
stateLabel.setText(crownSequencer.isIdle ? "Idle: true" : "Idle: false")
}
func crownDidBecomeIdle(_ crownSequencer: WKCrownSequencer?) {
updateCrownLabels()
}
func crownDidRotate(_ crownSequencer: WKCrownSequencer?, rotationalDelta: Double) {
updateCrownLabels()
}
}
At present (Xcode 6.2 beta 3) Apple have indicated that the Digital Crown will scroll page content up and down in third party apps, but apps cannot register to receive notifications from it or to use it as an input device. It seems highly likely that this is due to concerns about either latency leading to non-responsiveness, or battery life, given third party code is running solely in the WatchKit App Extension on the iPhone and therefore these events would have to be sent in a wireless stream back to the phone.
It is possible to use Force Touch as an input method in third party apps. At this point, I believe the only use Apple has advised for force touch in any application is to display a contextual menu, and third party developers have full access to this. You do not need to register to receive a force touch event. You simply create a menu in interface builder, add menu items to it, and then wire those menu items to IBActions in your WatchKit Extension. It is rather strange to not have to connect the menu to something equivalent to a force touch gesture recogniser, but when you try it, you'll just find it works. It may well be that this will continue to be the only access third party developers have to force touch, even after we have the ability to make native apps for the Watch later in 2015.
Apple have however encouraged developers to submit enhancement requests at http://bugreporter.apple.com so it'd be a good idea to do so, and ask for access to these APIs as a number of us already have.
At the moment there is no ability for custom event handlers for either input method. Apple employees on the Developer Forums have suggested submitting a feature request. I suspect we will get access to the Digital Crown API as soon as we can start creating native Apple Watch apps next year. At the moment it remains a significant limitation for data entry.
In watchOS 2, (included in Xcode 7 beta) Apple has added WKInterfacePicker
to allow you to register a delegate and respond to digital crown changes. You can check out the docs here.
In WatchOS 2 to use digital crown to select an item in a WKInterfacePicker:
In the watch app extension InterfaceController.h
@property (strong, nonatomic) IBOutlet WKInterfacePicker *TestSelector;
@property (strong, nonatomic) NSArray *TestsArray;
In the watch app extension InterfaceController.m
// Setup two items the user can select from in picker
WKPickerItem *pickerItem1 = [WKPickerItem alloc];
[pickerItem1 setTitle:@"First item in list"];
WKPickerItem *pickerItem2 = [WKPickerItem alloc];
[pickerItem2 setTitle:@"Second item in list"];
// Add items to array that will be used to set picker list
self.TestsArray = [[NSArray alloc ] initWithObjects:pickerItem1,pickerItem2, nil];
// Set list of items as choices in the picker list
[TestSelector setItems:self.TestsArray];
In interface builder, link the picker UI element to TestSelector as referencing outlet
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With