Chupamobile Blog

The App Source Code Marketplace. Buy Apps. Sell Apps.

03Dec

Are you tired of taking your iPhone out of your pocket to check messages? Do you want to be as Michael Knight and talk to your AI-friend through your wrist? Apple has made it possible thanks to its brand new Apple Watch and the amazing WatchKit framework.

WatchKit

First thing you need to know when developing an application for Apple Watch (also known as Watch app) is that these apps require an iPhone to be run. Therefore you will need two executables:

  • The Watch app that will run on the Apple Watch and contains the storyboards and the resource files needed to render the application’s user interface.
  • A WatchKit extension that will be run on the iPhone and contains the business code needed to manage the application’s UI and that will handle user interactions.

When developing an application for Apple Watch you will need to create a WKInterfaceController for each scene in your storyboard. This class has two important methods: initWithContext and willActivate that are responsible of retrieving the data to be displayed and initialize and configure visual components such as buttons or labels.

In case you want to create a view to display incoming UIUserNotificationSettings (for example an iMessage notification requesting you to meet for lunch with buttons to accept or reject the invitation) you need to instantiate WKUserNotificationInterfaceController, which inherits from WKInterfaceController.

Other interesting methods of the above interface controller classes are:

  • presentTextInputControllerWithSuggestions:completion: This method’s purpose is to display a modal screen for the user to input text, with the peculiarity that this method suggests phrases to be selected by the user.
  • updateUserActivity:userInfo: Gets the current application activity (for example a user tap on screen) and reports it to the user’s iPhone to deal with it.

An important concept in Watch apps is glances. Basically a glance is a screen in your application that shows specific information to the user, with the peculiarity that it can’t be scrolled and that are read-only. That’s the reason why a glance doesn’t contain components such as buttons, text inputs or slides.

In WatchKit we also find WKInterfaceDevice, a class used to contain information about the user configuration of its Apple Watch. This way we can take it into account when displaying content in the app.

Another important purpose of this class is caching created images on the Apple Watch so they can be used in the future avoiding the performance penalty when creating those images each time.

Some of its methods are:

  • preferredContentSizeCategory: It retrieves the font size customized by the user. This method is very important for accessibility-driven applications.
  • addCachedImage:name: Used to add the image specified as input argument in the device’s cache.
  • removeCacheImageWithName: It allows us to remove an image previously cached by specifying its name.

Finally, WatchKit comes with several interface objects to build your views, which are a custom version of UIKit’s objects. Hence we can find WKInterfaceButton, WKInterfaceDate, WKInterfaceImage, WKInterfaceLabel, WKInterfaceMap, WKInterfaceSlider, or WKInterfaceSwitch for example.

To be honest, I haven’t worn an Apple Watch yet but I’m sure it will mean a revolution in the way we make use of technologies. We are looking forward to receive your Watch app templates!