18
WatchKit Create Your First WatchKit App

Create your First Watchkit App

Embed Size (px)

Citation preview

Page 1: Create your First Watchkit App

WatchKit

Create Your First WatchKit App

Page 2: Create your First Watchkit App

IntroductionThe apple watch requires an iPhone paired with it to run

the apps without an iPhone the watch apps will not work.

For creating watch app, we need two separate bundles:

WatchKit app: The WatchKit app contains only storyboard and resource files associated with our apps UI.

WatchKit extension: The WatchKit extension contains the code for managing the WatchKit apps UI and responding user interactions.

Page 3: Create your First Watchkit App

App Structure

Page 4: Create your First Watchkit App

Watch app Launching

Page 5: Create your First Watchkit App

WatchKit FrameworkThe whole apple watch is managed by the few classes

the most used are as :

WKInterfaceController

WKUserInterfaceNotificationController

WKInterfaceDevice

WKInterfaceObject

Page 6: Create your First Watchkit App

WKInterfaceControllerWKInterfaceController in WatchKit is as same as

UIViewController in UIKit. WKInterfaceController is a lot more restricted and has a

different life cycle. There are different methods to work with as following.

Page 8: Create your First Watchkit App

WKInterfaceDeviceThis class contains basic information related to

the iWatch. This includes:

Screen bounds Scale Current locale

You can also use it to manage your images cache. WatchKit allows you to store up to 20 MB of cached images on the iWatch.

Page 9: Create your First Watchkit App

WKInterfaceObjectThis is the base class for all UI controls supported by WatchKit.

As we cannot use UI views from UIKit. All we can do is use the ones that WatchKit provides.

WKInterfaceButtonWKInterfaceDateWKInterfaceGroupWKInterfaceImageWKInterfaceLabelAnd more..

Page 10: Create your First Watchkit App

Creating Watch AppFirst create a new single view application iPhone

project and call it “WatchKitDemo.”

Page 11: Create your First Watchkit App

Create WatchKit Target

Select New > Target... from Xcode's File menu and choose WatchKit App from the iOS > Apple Watch section on the left.

Page 12: Create your First Watchkit App

Give the project name as “Watch” and uncheck include notification scene and include Glance scene.

Page 13: Create your First Watchkit App

When you click Finish, Xcode will create a number of files, groups, and targets.

Xcode will also create a scheme to run the WatchKit application in the iOS Simulator and it will ask you whether it should activate that scheme. Click Activate to activate it.

Page 14: Create your First Watchkit App

Project AnatomyBy adding a WatchKit application to our project, Xcode

has created two targets for us, one for the WatchKit extension, Watch Extension, and one for the WatchKit application, Watch App.

WatchKit application

WatchKit Extension

Page 15: Create your First Watchkit App

Create the user interface

Open the WatchKitDemo WatchKitApp folder and click on the Interface.storyboard file.

You should see a blank watch storyboard interface that you can drag UI controls onto.

Page 16: Create your First Watchkit App

Run WatchKit AppTo run Watch application, Select Watch scheme from

the Scheme List and select iPhone+Apple Watch Simulator.

Page 17: Create your First Watchkit App

Output

Page 18: Create your First Watchkit App