Upload
pawan-ramteke
View
42
Download
0
Embed Size (px)
Citation preview
WatchKit
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.
App Structure
Watch app Launching
WatchKit FrameworkThe whole apple watch is managed by the few classes
the most used are as :
WKInterfaceController
WKUserInterfaceNotificationController
WKInterfaceDevice
WKInterfaceObject
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.
WKUserInterfaceNotificationController
The WKUserNotificationInterfaceController class manages a dynamic user interface for a local or remote notification.
After initializing your interface controller, WatchKit calls the didReceiveRemoteNotification:withCompletion: or didReceiveLocalNotification:withCompletion: method to provide you with the payload data from the notification.
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.
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..
Creating Watch AppFirst create a new single view application iPhone
project and call it “WatchKitDemo.”
Create WatchKit Target
Select New > Target... from Xcode's File menu and choose WatchKit App from the iOS > Apple Watch section on the left.
Give the project name as “Watch” and uncheck include notification scene and include Glance scene.
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.
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
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.
Run WatchKit AppTo run Watch application, Select Watch scheme from
the Scheme List and select iPhone+Apple Watch Simulator.
Output