apple watch and watchkit - a technical overview
TRANSCRIPT
Apple Watch and Apple WatchKit
• A look at Apple Watch
• WatchKit
• Structure and life cycle
• WatchKit Framework
• Creating watch app
Content
A look at Apple Watch
Size & Screens
Sensors
• Gyroscope • Measures angular velocity
• Determine orientation of device
• Accelerometer • Measures non-gravitational acceleration
• Type of activity
• Intensity of activity
• Heart Rate monitor • Measure heart response to exercise
• Physical training apps
Connectivity
• Bluetooth Connectivity
• Connectivity with phone
• Connectivity with headphone or headsets.
• Wireless Charging
Input Buttons and Gestures
• Buttons
• Digital crown
• Conversation button
• Gestures
• Vertical scrolling
• Horizontal swipe
• Left edge swipe
• Force touch
• Tap
Communication
• Glance
• Notification
• Short-look interface
• Long-look interface
• Watch Interface
• Hierarchical navigation interface
• Page-base navigation interface
WatchKit
WatchKit
The 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 watch kit app contains only storyboard and resource files associated with our apps UI.
• WatchKit extension
The WatchKit extension contains the code for managing the WatchKit app’s UI and for responding user interactions.
Since both of these bundle are packed in side the ios app so during the installation of the app the system prompts the user to install the watchkit app when a paired watch is present
Structure and life cycle
App Structure
Communication between Watchkit App
VS Watchkit extension
Watch app Launching
Watch app life cycle
WatchKit Framework
A look at WatchKit framework
The whole apple watch is managed by the
few classes the most used are as
• WKinterfaceController
• WKUserNotificationInterfaceController
• WKInterfaceDevice
• WKInterfaceObject
A look at WatchKit framework
WKInterfaceController in WatchKit is the 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.
UIViewController WKInterfaceController
likeviewDidLoad Init
loadView awakeWithContext
ViewWillAppear WillActivate
ViewWillDisappear didDeactivate
A look at WatchKit framework
• WKUserNotificationInterfaceController
Its a WKInterfaceController subclass that is used to display
custom notification interfaces.
• WKInterfaceDevice
This class contains basic information related to the iWatch.
This includes screen bounds, scale and 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.
A look at WatchKit framework
• WKInterfaceObject
This 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.
• WKInterfaceButton
• WKInterfaceDate
• WKInterfaceGroup
• WKInterfaceImage
• WKInterfaceLabel
• And more
A look at WatchKit framework
• Watchkit layout
WatchKit does not use Auto layout to position it’s element.
This is because it might have been too complex for the
slow iWatch. Instead we have a layout system that
positions elements relative to each other in a horizontal or
vertical order.
A look at WatchKit framework
• Glances
The apple watch is designed so that user can have a quick
access to the information from the app on iPhone. This is
achieved by “Glance Interface controller” which is non-
scrollable view with the precise info and user can launch
the app by tapping in it or can close it.
Apple prohibits using any interfaceObject on this screen
because “Glances do not support interactivity—tapping
on a glance automatically launches your WatchKit app”
A look at WatchKit framework
• Static notification interfaces
It is a simplified version of notification appearance, it contains static image and text. Only notification text can be changed.
• Dynamic notification interfaces
It allow you to specify a custom controller to display notification. Dynamic notification are not interactive and should be designed to display the info, tapping on it will launch the application
Sharing data with containing iOS
appThis can be done with by different methods which are as following
• By NSUserDefault
we can create and init the object of user default by initiating with initwithSuiteName
• By NSFilemanager
we can create a shared container using group id [[NSFileManager defaultManager] containerURLForSecurityApplicationGroupIdentifier:@"group.com.swenggco.TodayExtensionApp"];
Sharing data with containing iOS
app
• By openParentApplication:reply: method
we can communicate directly with containing app by calling
the openParentApplication:reply: method, which iOS
launches or wakes the containing iOS app in the
background and calls
the application:handleWatchKitExtensionRequest:reply: m
ethod of its app delegate. The app delegate performs the
request using the provided dictionary and then returns a
reply to the WatchKit extension.
Creating watch app
• First we need to add watch app target to the iOS project.
To do this, select your project in the explorer and click the +
button at the bottom of the project.
Creating watch app
Select WatchKit App and hit Next
Select Finish when you are done
Now we have two new folders in
project directory
Setup an app group
App Groups are the scheme iOS uses to allow different apps to share data. If the apps have the right entitlements and proper provisioning, they can access a shared directory outside of their normal iOS sandbox.
To create groups we have to turn on “app groups” entitlement in Xcode for app and also for the extension.
When you flip that switch, Xcode will talk to the developer center to configure your app ID for app groups. Then you can select a group or create a new one.
Setup an app group
Setup an app group
Share a classes or framework
• We can also use a class a framework in watch extension
from the main project by selecting extension from “Target
membership” in “file inspector”.
Share a classes or framework
Now every thing is setup developing the watch
app. Add more WKinterfaceController start
building your watch app.
References
https://developer.apple.com/library/prerelease/ios/documen
tation/General/Conceptual/WatchKitProgrammingGuide/
https://developer.apple.com/library/prerelease/ios/documen
tation/UserExperience/Conceptual/WatchHumanInterfaceG
uidelines/index.html#//apple_ref/doc/uid/TP40014992-CH3-
SW1
http://swiftiostutorials.com/watchkit-tutorial/
http://stablekernel.com/blog/watchkit-sharing-app-data/
Need help launching your great Apple Watch App.
Swenggco SoftwareEmail: [email protected]
Web: www.swenggco-software.com
Thanks