As you know last year Apple introduced watchOS 2, which let you make native apps that run directly on your watch. So i was thinking we can also start Apple iWatch Programming and start Learning watchOS 2.
Start new project in Xcode. Select watchOS application from left menu.
On clicking next give a name to your app. You will see different options like “Include Notification Screen” , “Include Glance Screen” & “Include Complication“.
Clicking on “Include Notification Screen” adds a NotificationController class to your project. Its for displaying your notifications. Its a view controller not a UIViewController but WKUserNotificationInterfaceController. Use to display both local and remote notifications.
Clicking on “Include Glance Screen” adds a GlanceController class to your project. You may use it as nonscrollable screen that summarizes the current state an application is in. Glances are non-interactive and they shouldn’t contain controls, such as buttons and sliders. If a user taps on a Glance, the corresponding Watch app is launched
Clicking on “Include Complication” box adds a ComplicationController class to your project and configures the appropriate bits. When you go to view your extension target in Xcode, you’ll see checkboxes for the five potential classes of complication
There are no so much in this just a handful of classes listed below. All using these we will build best app for our iWatch 🙂
WKInterfaceController in WatchKit is the same as UIViewController in UIKit. WKInterfaceController has a different life cycle form UIViewController. We cannot use our standard Cocoa classes.
This is the designated initialiser for WKInterfaceController. The context parameter is used in order to pass any data from a previous interface controller to this one.
willActivate and didDeactivate
These are the methods you’d override in order to get notified whenever an interface controller becomes visible or is being dismissed.
willActivate is the place you will need to make sure your controller’s information is up to date and you can use
didDeactivate in order to clean up.
WKUserNotificationInterfaceController is a WKInterfaceController subclass that is used to display custom notification interfaces.
This includes screen bounds, scale and current locale, just some basic information related to the iWatch. You can also use it to manage your images cache.
The base class for all UI controls of WatchKit. We cannot use UIViews from UIKit. But it has its owns WatchKit objects:
WatchKit does not use Autolayout to position it’s element. We positions elements relative to each other in a horizontal or vertical order. We an change all this in Interface builder via the Attributes inspector.
Doing Some Coding
Drag drop a label on Interface Controller. Change its text. Now run your app.
Yay you did it. Congrats.
Our todays tutorial on Apple iWatch Programming : Learning watchOS 2 contains basic of iWatch Programming. In our next tutorial we will do deeper and build something exciting. Till then Happy Coding 😉