WatchKit App Development

Jun 07 2019Written by Manektech Team

WatchKit is a fundamentally a framework. Which is provided by Apple. We can develop interfaces for Apple Watch applications.

WatchKit is bundled with Xcode 6.2.

How to work WatchKit?

In WatchKit your application is divided into two parts which are as following :

Apple Watch
iPhone
Apple Watch :

It handles user input it doesn't really execute any of the code.
It contains only the UI assets like the storyboard and resource inventory.

iPhone :

It contain all the code of your app.

WatchKit handle all the communication between this two part iPhone and Apple Watch Application Development.

How does the Apple Watch communicate with your iPhone?
The Apple Watch influences both Bluetooth LE and Wi-Fi technologies to communicate with its alternate iPhone.

How can we build Apple Watch in Swift?

We can build app swift as well as in Objective - c.

Apple has provided two projects for WatchKit :

WatchKit Catalog: Using WatchKit Interface Elements – Objective-C.
Lister: A Productivity App – Objective-C and Swift.

Apple provided detail documentation of WatchKit Framework in swift and Objective- c.

Create Apple Watch app in swift step by step :


Step 1 : Open the Xcode , Select create new project and After selecting, enter the product name as "DemoWatchApp".

Step 2 : Now go to Xcode > File > New > Target.

Step 3 : Select "Application" in "WatchOS" section. Then click on WatchKit app. and press Next.

Step 4 : Give the name of your watch App "DemoWatchApp".

Step 5 : Presently you have effectively included "Watch Kit application" and "Watch Kit Extension" to your task. Here you can see two new Groups were made in File inspector. Named "DemoWatchApp" and "DemoWatchApp Extension". There are likewise two new targets included with main iPhone application.

In WatchKit App, You have three file. In those one is Interface.storyboard which is useful to structure and navigation flow for various watches (There are two sizes of watch : 38mm and 42mm).

Step 6 : In WatchKit Extension you have four built in files.
1. InterfaceController.swift for controller like ViewController in iOS.
2. ExtensionDelegate.swift like AppDelegate in iOS.

Step 7 : In Interface.storyboard select the controller. How to create new controller and assign a new class from the Xcode. To create new InterfaceController Drag and Drop Interface Controller from Object library.

Step 8 : Now you can set title for controller to show on Applewatch.

Step 9 : Now drag and drop the Table from the object library to WKInterfaceController.
Step 10 : Open Assistant Editor > Select Table from Document outline > Drag and Drop to InterfaceController.swift file to create Outlet . On the right side in Attribute inspector you can set table's property.

Step 11 : Now create class for table's row named "DemoTableCell" (As we are creating UITableViewCell's custom class). Here Parent class must be NSObject type. Then select Row Controller from Document outline. And in identity Inspector assign a new class name to row controller.

class DemoTableCell : NSObject {

}

Step 12 : Drag and Drop label in group of row controller. Create outlet in row class. You can set property of label from Attribute inspector.

class DemoTableCell : NSObject {
@IBOutlet var labelFriendName: WKInterfaceLabel!
}

Step 13 : Select RowController from Document outline then select Attribute inspector. Now give a name in identifier. This name will be useful for reuse of row in table.

Step 14 : Created simple string Array to Show name in watch.

let arrList = [“Bob”,”John”,”Mark”]

Step 15 : To run Watch App, select scheme for Watch App and then select simulator.

Some Other things about Watch app

How many Apple Watches can pair with one iPhone ?
We can pair one Watch with one iPhone at a time.

Can we use the Apple Watch while in Airplane Mode?
Yes, we can use Apple Watch while in Airplane Mode.

Can we pair my Apple Watch with an iPad?
No, Apple Watch only pairs with an iPhone.

Design of watch
Apple Watch available in two sizes ?— ?38mm and 42mm.
The smaller screen is 340 pixels by 272 pixels, and the larger is 390 pixels by 312 pixels.

How can we add animation to Watch app ?
We can display animations on the Apple Watch by image sequences.

Contact us

Here to Help ambitious people TRANSFORM the Digital Solutions!