Hi guys, I’m currently working on making it easy for Cordova devs to add AppleWatch support.
The current solutions (plugins) are excellent (and I’m borrowing ideas) but as most of us are JavaScript programmers the task of creating a storyboard and related controllers (let alone wiring of the communication bits like Wormhole and OpenParentApplication) is too high a barrier IMO.
The goal of this plugin is you don’t have to touch native code at all to create a WatchKit extension: https://github.com/Telerik-Verified-Plugins/AppleWatch
For instance, if you want a user to give feedback in your Watch app, you can add a button via JS in your index.html like this:
'userInputButton': {
'inputMode': 'WKTextInputModeAllowAnimatedEmoji',
'suggestions': ['Yes', 'No', 'Maybe'],
'title': {
'value': 'Going?',
'color': '#FFFFFF', // label color (red)
'font': {
'size': 10
}
},
'color': '#CC0000', // button color
'callback': 'onVoted'
},
Aftter pressing the red button (not shown here) in the Watch app, the user will see this (standard WatchKit) UI:
And after selecting an option (like ‘Yes’), the JS callback ‘onVoted’ will be called, which can be anything, even a request to your server’s REST API, because your connected phone app will get some background time (even if it wasn’t running on the phone!).
function onVoted(val) {
console.log("The user selected this value on the watch: " + val);
}
Force Touch context menu
That’s all cool, but it gets really funky when you can program a Force Touch event in JavaScript(!) WatchKit allows a ‘context menu’ per interfacecontoller (‘page’), so you can send the context menu config to the watch from JS as well. Here’s a menu showing a Play and Resume option:
'contextMenu': {
// configure up to 4 items
'items': [
{
'title': 'Play',
'iconNamed': 'Play', // https://developer.apple.com/library/ios/documentation/WatchKit/Reference/WKInterfaceController_class/index.html#//apple_ref/doc/c_ref/WKMenuItemIcon
'callback': 'onContextMenuPlay'
},
{
'title': 'Resume',
'iconNamed': 'Resume',
'callback': 'onContextMenuResume'
}
]
Which results in this UI after force touching the watch (or long pressing in the simulator):
And of course the JS callback onContextMenuPlay or onContextMenuResume will be invoked after the user selected the option.
Work in progress
The plugin is in alpha, so things will break and not all ideas have been implemented yet. This is a good time to give feedback if you have any helpful thoughts. We’re planning on releasing a 1.0 later this month.
Any and all feedback is much appreciated!