Mallow's Blog

iOS and watchOS – A comparison for beginners

It has been almost 22 months since the introduction of watchOS and there are a lot of useful watch apps in the AppStore. The development for watch has been considerably increasing, especially health apps. While learning watchOS, I started noticing certain similarities and differences between iOS and watchOS and wanted to present them here.

First, I would start with the way watch apps are organised. They are built as extensions to iOS apps. Unlike iOS, there are two bundles: Watch app and WatchKit extension bundles. An interesting fact here is: separate targets are to be created for each of the bundles and it becomes harder when we realise that we need to have separate bundle IDs and profiles too. Thanks to the Automatic Signing in the latest releases of Xcode(8.0,*), we need not spend much during the development phase.

AppDelegate : iOS :: ExtensionDelegate : watchOS:

The ExtensionDelegate(not necessary to have the same name, you can have your own name, but make sure it extends WKExtensionDelegate protocol) does the work for the watch similar to what AppDelegate does for the iPhone/iPad. It has got similar functionality in:

  1. applicationDidFinishLaunching
  2. applicationDidBecomeActive or applicationWillResignActive
  3. applicationWillEnterForeGround or applicationDidEnterBackGround

Life cycle of WatchOS

Image Courtesy: developer.apple.com

LifeCycle

The watch app can be supposed to be at different states like Active, Inactive, Background, Suspended similar to iOS. If the app goes to background, the time taken for it to get suspended is very less when compared to iOS.

Performance:

Unlike the iOS app, it is not considered wise to build long running apps since watch apps interact with the user for just a short duration. Also, background tasks are to be avoided. Once the app goes to background, it gets suspended sooner. For a larger variety of apps, Apple watch apps are considered to have sufficient information and not the entire iOS app.

Communication:

To share data with the companion iPhone app, there are two ways possible:

  1. NSUserDefaults – we can store data in shared user defaults.
  2. Shared Coredata

But in order establish communication between the watch app and the iOS companion app, Apple had introduced a framework called WatchConnectivity. Using this framework, we can send data to and from watch app and iOS app.

DataBase:

Watch has now got its own DB. Earlier, the data was shared between the iPhone and watch. But now, in addition to sharing, we can also create a local DB for watch and iPhone separately. This makes persistence easier from the watch.

Controllers:

The job of a viewController in iOS is to manage the views and provide data to them from the models. The same is done by interfaceControllers in watchOS, but instead of “views”, they are termed “interfaces” and the controllers need to extend WKInterfaceController. It has got 3 important methods which are overridden for proper usage:

  1. init
  2. awakeWithContext – to load data – (analogous to viewDidLoad of iOS)
  3. willActivate – to do last minute updates – (analogous to viewWillAppear of iOS)

Interfaces vs Views:

There is no UIView in WatchKit. This introduces a lot of difficulties if we want to use a customized UI. Instead, we have been provided with WKInterfaceObject which is similar to UIView but with a lot of restrictions. One main disadvantage is that: “We cannot assign user-defined subclasses for interfaces created in the storyboard.” As another negative, “We cannot set constraints between elements in the storyboard”. The elements are adjusted automatically depending on the orientation we specify. They are adjusted either horizontally or vertically.

Instead of UIViews, we can also have groups(WKInterfaceGroup, a subclass of WKInterfaceObject) which provide the same functionalities as views. But the constraint restriction is also present here. So the major difference is regarding the layout system. Also, when we try to align an element using left, top, right, bottom, centre, the system chooses a position on its own relative to the surrounding elements. To set up a custom UI, groups play an important role. We can have multiple groups in different combinations, one inside the other and along with the top, left, right and bottom constraints to make the UI we want.

There are few other drawbacks like: there is no background image for the buttons. But buttons can be considered as a single object or a grouped one. In case of a grouped button, we can have at most 1 element as a child.

These might seem a bit harsh on Apple from the developers’ point of view. But one thing we need to keep in mind is that Watch is a tiny device and whatever we show on it should be short, simple, but complete. That is one of the reasons why Apple has not let the developers take advantage of the SDK to make the watch so much customized. Or else, the basic purpose of the development of watch apps – Fast and Simple Interface – gets ruined.

Apple watches have a force touch capability like 3D touch for iPhones of latest models. A menu appears on the screen and the user is asked to choose one action to perform. This can be done inside the app as well.

An important concept present in Apple Watches is the Complication. It displays the details of the app on the watch face. A watch face is what a user sees when he opens or activates the watch. There is an option to keep the complications updated regularly. For example, a weather app might show, the current weather at the location where the watch is present or the next remainder along with the timing, etc. A close similarity with iOS can be found in the Today widgets. Complications are not the same as Today widgets, but their purpose is the same.

 

 

 

Sriram K,
Junior Developer iOS Team,
Mallow Technologies.

 

Leave a Reply

%d bloggers like this: