IOS development: WatchKit application highlights
WatchKit application architecture
The WatchKit application is an executable file running on Apple Watch. It includes the storyboard and the resource files required for rendering the screen.
The WatchKit extension is an executable file running on the iPhone. It includes the logic code for managing the application interface and handling user interaction operations.
These two parts need to be run together for the normal use of the program interface. Typical steps for user-to-application interaction are as follows:
The user interacts with the WatchKit application.
The WatchKit application analyzes the interaction and selects the storyboard to be managed.
WatchKit communicates with the iPhone to run the WatchKit extension.
The WatchKit extension initializes and creates the object that needs to be provided to the WatchKit application storyboard.
Storyboard generates scene Based on the objects created by WatchKit extension and displays it in Apple Watch.
The WatchKit application and WatchKit will share some information until the user stops using the WatchKit application. In this case, iOS will sleep the WatchKit extension until new user interactions exist.
The figure below demonstrates the process:
Storyboard responds to user operations and configures the screen content to be displayed. This is due to the interface controller object (WKInterfaceController instance), which is equivalent to the view controller in iOS.
Unlike view controller, interface controller does not manage the actual view on the screen. WatchKit processes the view in a transparent manner. Generally, a WatchKit application has multiple interface controllers to display different data types, but only one interface controller is displayed at the same time.
WatchKit application Lifecycle
There are three ways to start a WatchKit application:
Click the icon on the Apple Watch home screen.
The glance between the user and the application.
Interaction between users and notifications.
In each of the above methods, the WatchKit application and the WatchKit extension will be initialized. Based on the preceding startup methods, WatchKit loads scene using the corresponding storyboard and requests the WatchKit extension to initialize the corresponding interface controller.
The following figure demonstrates the related process:
Interface controller objects manage Related interactions on the user interface. When a user interacts with an application on Apple Watch, The WatchKit extension runs. Once the user stops interaction or exits from the program, iOS will disable the current interface controller and sleep the extension. Between users and Apple Watch, this interaction method is very simple. interface controller should be lightweight and fast to execute tasks.
The following figure demonstrates the related process: