Creating Your First WatchKit App

Craig Dunn

A new release of Xamarin’s Apple WatchKit support is now available for download, including initial support for the Xamarin iOS Designer. This post walks you through steps to create your first Watch Kit app (described in more detail in our WatchKit getting started guide).

File > New Watch App

Start with a new or existing iOS app, then add a Watch App. Xamarin Studio automatically creates both required projects: a Watch App and a Watch Extension.

Reference the Watch Extension

Before you can use the iOS Designer, or deploy and test in the iOS Simulator, reference the Watch Extension from your iOS app; and reference the Watch App from the Watch Extension.

Don’t forget to set the Bundle Identifiers correctly in each Info.plist.

Design the Watch UI

Double-click to open the Interface.storyboard in the iOS Designer.

Drag a Label and a Button onto the default InterfaceController. Don’t forget to give them a Name in the Properties pane (eg. myLabel and myButton).

Double-click on the button in the Designer to create a handler for when it’s pressed. Press enter to place the method in the code.

Just Add Code

Add the following code to the InterfaceController.cs file, which updates the label each time the button is pressed:

int clickCount = 0;

partial void myButton_Activated (WatchKit.WKInterfaceButton sender)
{
    var msg = String.Format("Clicked {0} times", ++clickCount);
    myLabel.SetText(msg);
}

Test in the Simulator

Ensure the Watch Extension project is set to be the start-up project, then select an iPhone 6 simulator and start debugging. Tip: use Bezel to see the simulator rendered inside an Apple Watch frame.

Simulator

If you don’t see the simulated watch screen, select Hardware > External Displays in the iOS Simulator.

Video Walkthrough

You can also see the above steps on getting started with WatchKit in action in this short video:

Try it out today!

You can download our WatchKit Preview installers from the Xamarin developer portal (make sure you also have Xcode 6.2 beta 5 from Apple). Start with the WatchKit Preview guides and WatchKit samples.

Discuss this blog post in the Xamarin Forums.

0 comments

Discussion is closed.

Feedback usabilla icon