📜 ⬆️ ⬇️

First look at the Apple Watch SDK



The Apple Watch SDK, announced in June and just released, caused a lot of controversy and questions. The first version has limited functionality, and version 2.0 is just around the corner, you need to wait a few more months. Impressions of the new SDK developers have developed different. Some are disappointed by the large number of restrictions, others, on the contrary, are impressed by the fact of the release. There is also a “stratum” of those who adopted the new product with sufficient restraint. But in any case, the vast majority of developers are happy to release new interesting fun.

The first thing that catches the eye in the SDK is the designation of Apple Watch users. These are not “users” or “mobile users”, or even “users of watches”. They are wearers. It sounds rather strange, because if the user uses , that is, interacts with the gadget, the carrier simply wears , and this hints at passive use. Of course, the Apple Watch language will not turn to be called a passive device, they combine the traditional functionality of watches with the capabilities of modern electronic gadgets, especially in conjunction with the iPhone. By the way, not so long ago, traditional telephones have also become something more than just devices for calling, the story is developing in a spiral. As for the carrier , this term no longer seems strange. Instead of “Apple Watch user”, you can simply say “carrier”, and this will sound less ambiguous.

Device and interface


We will not give here all the parameters of the clock, we will dwell only on what is directly related to software development. In fact, there are two Apple Watch models with different screen resolutions, so developers and designers need to consider this:

Both models use retina displays. There is no need to explain that developers should take care to adapt their applications for both types of screens.
')

Connection


Communication with the iPhone via Bluetooth 4.0. NFC is also available. Having connected to the iPhone, the watch can use both its Wi-Fi module and cellular connection. Although Apple itself declares that the watch has its own Wi-Fi module (802.11b / g).

Interaction with the device


A user (or carrier) can interact with the clock in four different ways:

What restrictions are imposed from the point of view of user interaction:

An example of the context menu from Apple WatchKit Guide:



Interface


The screen size and design features impose their limitations on the user interface. Also, hardware can be used to make a contribution. It is hoped that a number of restrictions will be lifted in future versions of the SDK, although such things cannot be accurately predicted.

And the first limitation is connected with the way of creating the user interface - it is possible only with the help of Storyboards.

Navigation


WatchKit offers two mutually exclusive ways to navigate within the application:

Unfortunately, it is impossible to combine both these models in one application. It is necessary to choose some one. However, each interface controller may represent a modal controller. And that, in turn, can be either a single controller or a set of controllers, ordered by page.

Interface elements


Apple Watch SDK uses 11 types of items:

Layouts


The “group” component is used to combine interface elements horizontally or vertically. Items will be placed automatically depending on the size. It is possible to create nested groups.

Unfortunately, Auto-Layout is not available in WatchKit. But, given the fact that the interface is much simpler in clocks than in iOS, this is not a particularly noticeable drawback.

To create lists, the “table” component is used, in which the data is arranged in one column, just like in the case of UITableView . However, the delegation pattern is not used here — first, the number of rows is specified, and then they are all filled in the loop with data. The good news is that you can still customize cells.

Glance interfaces


Glance is a single, non-interactive, informational pages only, which cannot even be scrolled. They are used only to display small data, often associated with progress in performing some operation or the time remaining until the end. Of all the types of user interaction, only a single tap is available, through which the application associated with glance is launched, while optionally passing context to the application so that it can show the desired controller after launch.

For example, a weather application might use glance to display the current temperature. By pressing the application starts with more complete information.

Here is an example of glance from Apple WatchKit Guide:



Detailed information on creating and using glance can be obtained from the WatchKit Programming Guide .

Notifications


There are two types of them: short (short look) and long (long look).

Short notifications are used to inform about various events, to display warnings and notifications. When the user (carrier) drops his hand with the clock, the notification disappears. The layout of such notifications is very simple and consists of the application icon, its name and the title of the notification itself.



If for some time not to lower the hand with the clock or to tap on a short notification, then a long notification will appear on the screen. It contains more information about the event and supports interaction via custom buttons. Pressing them can send notifications to applications. Unlike short notifications, the user must reset the notification display at the touch of a button at the very bottom.



Additional information on the use of notifications can be obtained from the documentation .

Architecture


If you downloaded the WatchKit version of Xcode (at the moment 6.2 beta), then don’t be alarmed by the fact that you didn’t find a template for the Apple Watch application in it:



The clock application cannot exist separately - it can only be added as an App Extension to an existing iOS application.



The reason is the system architecture and the way that the clock interacts with the corresponding iOS application:



When the application starts on the clock, the interconnected iOS extension automatically starts. They work as a single mechanism; for example, the “hourly” application shows the weather and interacts with the user, while the iOS extension does the rest. In fact, no software code is executed on the clock: all calculations are performed in the smartphone. This is very similar to the “browser - web application” scheme, in which all logical calculations are performed on the server, and the client only displays the result and interacts with the user.

An application installed in a watch consists of a Storyboard and interconnected static resources packaged in a bundle that is static, that is, you cannot change or add resources, screens, images, etc. during execution. The described static client-server model imposes several other restrictions, and this is one of the main reasons why many developers did not show much enthusiasm for the release of the SDK.

Criticized and the lack of support for animation. The only way to get around this restriction at least is to pack individual frames into an application and quickly display a sequence of images. If you rename all frames in order, you can automate the animation process directly from Interface Builder. However, the same can be done directly in the code.

Apple also announced that the new version of the SDK will support native applications, but without any details.

A couple of words about the framework


WatchKit does not use, inherit or are part of UIKit. The new framework was specifically designed specifically for watches, for their small screen and modest features. The framework consists of only 15 classes, of which 11 are user interface components (shortcut, button, etc.).

The most important class in the framework is WKInterfaceController , an analogue of UIViewController from UIKit. The fact that in iOS and OS X is called the view controller (view controller), in Apple Watch - interface controller (interface controller).

Without going into the subject, the most noticeable improvement over UIKit was the introduction of a pattern for exchanging data between interface controllers. The controller initialization looks like this:
Swift init(context: AnyObject?) // nil

and allows you to pass an arbitrary object to the controller instance (called context in all APIs). This simplifies and standardizes the transfer of data from one interface controller to another. The only drawback is that the object is not a generic type, but an opaque AnyObject , which must be AnyObject to the expected type inside the initializer in the AnyObject controller. This is probably done because of the need (or desire) to continue using Objective-C with WatchKit.

The life cycle of an interface controller is simplistic compared to a regular controller. It contains only three transitions:

In addition to displaying content, the interface controller is also responsible for:


Can WatchKit be considered complete?


Due to a number of limitations, this SDK can be called a rather immature product. There is no support for native applications for watches, and the watches themselves are not yet sold. Therefore, developers can not even test their applications yet, feel the new device. Yes, there is an emulator, but it is not independent, but works as an external display for an iOS emulator (menu Hardware -> External Displays). And the best emulator will not be able to completely replace a living device.

In fact, this is a kind of preview, beta version, seed for appetite, which will be developed with each new release. We can only play with what we have and squeeze the maximum out of it.

Source: https://habr.com/ru/post/245369/


All Articles