{"id":16617,"date":"2015-02-12T10:45:33","date_gmt":"2015-02-12T18:45:33","guid":{"rendered":"http:\/\/blog.xamarin.com\/?p=16617"},"modified":"2019-04-02T16:05:05","modified_gmt":"2019-04-02T23:05:05","slug":"your-first-watch-kit-app","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/xamarin\/your-first-watch-kit-app\/","title":{"rendered":"Creating Your First WatchKit App"},"content":{"rendered":"<p>\t\t\t\t<a href=\"\/wp-content\/uploads\/sites\/44\/2019\/04\/Simulator.png\"><img decoding=\"async\" class=\"alignright wp-image-16624\" src=\"\/wp-content\/uploads\/sites\/44\/2019\/04\/Simulator.png\" alt=\"\" width=\"134\" height=\"200\" \/><\/a>A new release of Xamarin&#8217;s Apple WatchKit support is now <a href=\"http:\/\/developer.xamarin.com\/guides\/ios\/watch\/installation\/\">available for download<\/a>, 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 <a href=\"http:\/\/developer.xamarin.com\/guides\/ios\/watch\/getting-started\/\" target=\"_blank\">WatchKit getting started guide<\/a>).<\/p>\n<h2>File &gt; New Watch App<\/h2>\n<p>Start with a new or existing iOS app, then add a <b>Watch App<\/b>. Xamarin Studio automatically creates both required projects: a Watch App and a Watch Extension.<\/p>\n<p><a href=\"\/wp-content\/uploads\/sites\/44\/2019\/04\/new-550.png\"><img decoding=\"async\" class=\"alignnone wp-image-16831 size-full\" src=\"\/wp-content\/uploads\/sites\/44\/2019\/04\/new-550.png\" alt=\"\" width=\"550\" height=\"192\" \/><\/a><\/p>\n<h2>Reference the Watch Extension<\/h2>\n<p>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.<\/p>\n<p><a href=\"\/wp-content\/uploads\/sites\/44\/2019\/04\/ref-460.png\"><img decoding=\"async\" class=\"alignnone wp-image-16832 size-full\" src=\"\/wp-content\/uploads\/sites\/44\/2019\/04\/ref-460.png\" alt=\"\" width=\"460\" height=\"156\" \/><\/a><\/p>\n<p>Don&#8217;t forget to <a href=\"http:\/\/developer.xamarin.com\/guides\/ios\/watch\/installation\/#Set_Project_References_and_Identifiers\" target=\"_blank\">set the Bundle Identifiers correctly<\/a> in each <code>Info.plist<\/code>.<\/p>\n<h2>Design the Watch UI<\/h2>\n<p>Double-click to open the <b>Interface.storyboard<\/b> in the iOS Designer.<\/p>\n<p>Drag a <code>Label<\/code> and a <code>Button<\/code> onto the default <code>InterfaceController<\/code>. Don&#8217;t forget to give them a <b>Name<\/b> in the Properties pane (eg. <code>myLabel<\/code> and <code>myButton<\/code>).<\/p>\n<p><a href=\"\/wp-content\/uploads\/sites\/44\/2019\/04\/ide-550.png\"><img decoding=\"async\" class=\"alignnone wp-image-16833 size-full\" src=\"\/wp-content\/uploads\/sites\/44\/2019\/04\/ide-550.png\" alt=\"\" width=\"550\" height=\"281\" \/><\/a><\/p>\n<p>Double-click on the button in the Designer to create a handler for when it&#8217;s pressed. Press <em>enter<\/em> to place the method in the code.\n<a href=\"\/wp-content\/uploads\/sites\/44\/2019\/04\/handler-550.png\"><img decoding=\"async\" class=\"alignnone wp-image-16834 size-full\" src=\"\/wp-content\/uploads\/sites\/44\/2019\/04\/handler-550.png\" alt=\"\" width=\"550\" height=\"97\" \/><\/a><\/p>\n<h2>Just Add Code<\/h2>\n<p>Add the following code to the <b>InterfaceController.cs<\/b> file, which updates the label each time the button is pressed:<\/p>\n<pre><code>int clickCount = 0;\u2028\r\npartial void myButton_Activated (WatchKit.WKInterfaceButton sender)\r\n{\r\n    var msg = String.Format(\"Clicked {0} times\", ++clickCount);\r\n    myLabel.SetText(msg);\r\n}<\/code><\/pre>\n<h2>Test in the Simulator<\/h2>\n<p>Ensure the <b>Watch Extension project<\/b> is set to be the start-up project, then select an iPhone 6 simulator and start debugging. <i>Tip:<\/i> use <a href=\"http:\/\/infinitapps.com\/bezel\/\" target=\"_blank\">Bezel<\/a> to see the simulator rendered inside an Apple Watch frame.<\/p>\n<p><a href=\"\/wp-content\/uploads\/sites\/44\/2019\/04\/Simulator.png\"><img decoding=\"async\" class=\"aligncenter size-medium wp-image-16624\" src=\"\/wp-content\/uploads\/sites\/44\/2019\/04\/Simulator-201x300.png\" alt=\"Simulator\" width=\"201\" height=\"300\" \/><\/a><\/p>\n<p>If you don&#8217;t see the simulated watch screen, select <b>Hardware &gt; External Displays<\/b> in the <b>iOS Simulator<\/b>.<\/p>\n<h2>Video Walkthrough<\/h2>\n<p>You can also see the above steps on getting started with WatchKit in action in this short video:<\/p>\n<p><iframe width=\"640\" height=\"390\" src=\"https:\/\/www.youtube.com\/embed\/J2kgtdCnVoU\" frameborder=\"0\" allowfullscreen><\/iframe><\/p>\n<h2>Try it out today!<\/h2>\n<p>You can download our WatchKit Preview installers from the <a href=\"http:\/\/developer.xamarin.com\/guides\/ios\/watch\/installation\/\">Xamarin developer portal<\/a> (make sure you also have Xcode 6.2 beta 5 from <a href=\"https:\/\/developer.apple.com\/devcenter\/ios\/\" target=\"_blank\">Apple<\/a>). Start with the <a href=\"http:\/\/developer.xamarin.com\/guides\/ios\/watch\/\">WatchKit Preview guides<\/a> and <a href=\"http:\/\/developer.xamarin.com\/samples\/ios\/Watch\/\">WatchKit samples<\/a>.<\/p>\n<p><a href=\"http:\/\/forums.xamarin.com\/discussion\/32583\/\">Discuss this blog post in the Xamarin Forums.<\/a>\t\t<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A new release of Xamarin&#8217;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 &gt; New Watch App Start with a new or existing [&hellip;]<\/p>\n","protected":false},"author":570,"featured_media":39167,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[2,3,10],"tags":[6,4],"class_list":["post-16617","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-developers","category-enterprise","category-leadership","tag-ios","tag-xamarin-platform"],"acf":[],"blog_post_summary":"<p>A new release of Xamarin&#8217;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 &gt; New Watch App Start with a new or existing [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/xamarin\/wp-json\/wp\/v2\/posts\/16617","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/xamarin\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/xamarin\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/xamarin\/wp-json\/wp\/v2\/users\/570"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/xamarin\/wp-json\/wp\/v2\/comments?post=16617"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/xamarin\/wp-json\/wp\/v2\/posts\/16617\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/xamarin\/wp-json\/wp\/v2\/media\/39167"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/xamarin\/wp-json\/wp\/v2\/media?parent=16617"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/xamarin\/wp-json\/wp\/v2\/categories?post=16617"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/xamarin\/wp-json\/wp\/v2\/tags?post=16617"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}