apple watch
play

Apple Watch Mobile Application Development in iOS School of EECS - PowerPoint PPT Presentation

Apple Watch Mobile Application Development in iOS School of EECS Washington State University Mobile Application Development in iOS 1 Outline Xcode configuration WatchKit Notifications Complications Sensors Mobile


  1. Apple Watch Mobile Application Development in iOS School of EECS Washington State University Mobile Application Development in iOS 1

  2. Outline • Xcode configuration • WatchKit • Notifications • Complications • Sensors Mobile Application Development in iOS 2

  3. Xcode Configuration: New Project New in watchOS 6 (released Sep 2019): Independent watchOS apps Mobile Application Development in iOS 3

  4. Xcode Configuration: Add to Existing Project File à New à Target Mobile Application Development in iOS 4

  5. WatchKit App and Extension • WatchKit App – Storyboard – Storyboard assets • WatchKit Extension – App code Mobile Application Development in iOS 5

  6. Interface Storyboard Mobile Application Development in iOS 6

  7. Interface Storyboard Mobile Application Development in iOS 7

  8. Interface Storyboard Mobile Application Development in iOS 8

  9. Interface Controller InterfaceController.swift import WatchKit import Foundation class InterfaceController: WKInterfaceController { @IBAction func pageTwoManualTapped() { pushController(withName: "Page Two", context: "Hello Manually") } override func contextForSegue(withIdentifier segueIdentifier: String) -> Any? { if segueIdentifier == "toPageTwoAuto" { return "Hello Automatically" } return nil } } Mobile Application Development in iOS 9

  10. Page Two Interface Controller PageTwoInterfaceController.swift import WatchKit import Foundation class PageTwoInterfaceController: WKInterfaceController { @IBOutlet weak var messageLabel: WKInterfaceLabel! override func awake(withContext context: Any?) { super.awake(withContext: context) // Configure interface objects here. if let message = context as? String { messageLabel.setText(message) } } } Mobile Application Development in iOS 10

  11. Other Interface Objects Mobile Application Development in iOS 11

  12. Alerts and Action Sheets @IBAction func alertTapped() { let action1 = WKAlertAction(title: "Yes", style: .default, handler: {print("Yes")}) let action2 = WKAlertAction(title: "No", style: .destructive, handler: {print("No")}) presentAlert(withTitle: "Alert", message: "Are you okay?", preferredStyle: .sideBySideButtonsAlert, actions: [action2,action1]) } Mobile Application Development in iOS 12

  13. Notifications Mobile Application Development in iOS 13

  14. Notifications Short Look watchOS uses same technique as iOS • – Call requestAuthorization on watch – Handle notifications using didReceive Long Look and willPresent – Schedule UNNotificationRequest using UNUserNotificationCenter.add – Remote and background notifications can now be sent directly to watch Watch first displays Short Look, then • Long Look Mobile Application Development in iOS 14

  15. Authorize Notifications ExtensionDelegate.swift import WatchKit import UserNotifications class ExtensionDelegate: NSObject, WKExtensionDelegate { func applicationDidFinishLaunching() { // Perform any final initialization of your application. let center = UNUserNotificationCenter.current() center.requestAuthorization(options: [.alert]) { (granted, error) in if granted { print("notifications allowed") } else { print("notifications not allowed") } } } } Mobile Application Development in iOS 15

  16. Notification Interfaces Static Interface • – Simple elements (fast) Dynamic Interface • – Outlets in NotificationController – No interactive elements – If takes too long, uses Static Dynamic Interactive Interface • – Allows interactive elements – Outlets/Actions in NotificationController Mobile Application Development in iOS 16

  17. Notification Interfaces Interface Load Order: (1) Dynamic Interactive, (2) Dynamic, (3) Static Mobile Application Development in iOS 17

  18. Schedule Notifications Careful • Make sure Notification – Category Name is empty Or, make sure – notifications have same category identifier Mobile Application Development in iOS 18

  19. Simulate Push Notification Mobile Application Development in iOS 19

  20. Schedule Notification Programmatically InterfaceController.swift import UserNotifications func scheduleNotification() { // Same as in Notifications lecture notes let content = UNMutableNotificationContent() content.title = "Hey!" content.body = "What’s up?" content.userInfo["message"] = "Yo!" // If Notification Category set in Storyboard, then set here too // content.categoryIdentifier = "myCategory" // Configure trigger for 5 seconds from now let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 5.0, repeats: false) // Create request let request = UNNotificationRequest(identifier: "NowPlusFive", content: content, trigger: trigger) // Schedule request let center = UNUserNotificationCenter.current() center.add(request, withCompletionHandler: { (error) in if let err = error { print(err.localizedDescription) } }) } Mobile Application Development in iOS 20

  21. Handle Notifications NotificationController.swift import WatchKit import Foundation import UserNotifications class NotificationController: WKUserNotificationInterfaceController { @IBOutlet var dynamicInteractiveLabel: WKInterfaceLabel! override func didReceive(_ notification: UNNotification) { let title = notification.request.content.title dynamicInteractiveLabel.setText(title) } } Mobile Application Development in iOS 21

  22. Complications Mobile Application Development in iOS 22

  23. Complications ClockKit framework • CLKComplicationDataSource • Provide data for a specific date/time • Time Travel allows user to view past, present and future • complication data (e.g., appointments) See different styles at developer.apple.com/design/human-interface- • guidelines/watchos/app-architecture/complications Mobile Application Development in iOS 23

  24. Required Delegate Methods • In ComplicationController.swift – getSupportedTimeTravelDirections(complication, handler) • Send .backward, .forward, neither, or both to handler – getCurrentTimelineEntry(complication, handler) • Create and pass time line entry to handler Mobile Application Development in iOS 24

  25. getCurrentTimeLineEntry For desired complication families (.circularSmall, etc.) • – Create a CLKComplicationTemplate, e.g., • CLKComplicationTemplateGraphicCircularImage • CLKComplicationTemplateCircularSmallSimpleText – Create and set providers for template, e.g., • CLKFullColorImageProvider(UIImage) • CLKSimpleTextProvider(String) – Create time line entry for template at date • CLKComplicationTimelineEntry(Date, CLKComplicationTemplate) – Send entry to handler Mobile Application Development in iOS 25

  26. Complications import ClockKit class ComplicationController: NSObject, CLKComplicationDataSource { func getSupportedTimeTravelDirections(for complication: CLKComplication, withHandler handler: @escaping(CLKComplicationTimeTravelDirections) -> Void) { handler([.forward, .backward]) // or .forward, or .backward, or [] } } Mobile Application Development in iOS 26

  27. Complications func getCurrentTimelineEntry(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationTimelineEntry?) -> Void) { if (complication.family == .graphicCircular) { // Construct template with image, open gauge, and text let template = CLKComplicationTemplateGraphicCircularImage() let image = UIImage(named: "Complication/Graphic Circular") template.imageProvider = CLKFullColorImageProvider(fullColorImage: image!) // Create the timeline entry. let entry = CLKComplicationTimelineEntry(date: Date(), complicationTemplate: template) handler(entry) } else { handler(nil) } } Mobile Application Development in iOS 27

  28. Complications: Testing (1) Configure Complications (2) Choose Complication scheme Mobile Application Development in iOS 28

  29. Complications: Testing (3) Customize clock face Deep Customize Goto Press clock Swipe face to end Goto Note: Shift-Command-1/2 clock Rotate to set shallow/deep press face crown in simulator. to select Mobile Application Development in iOS 29

  30. Sensors • CoreMotion framework – Accelerometer – Gyroscope • CoreLocation framework – GPS • HealthKit framework – Heart rate Mobile Application Development in iOS 30

  31. Other Elements • Core Data • SpriteKit Mobile Application Development in iOS 31

  32. Resources WatchKit framework • – developer.apple.com/documentation/watchkit – Notifications developer.apple.com/documentation/watchkit/adding_notifications_to_your_watchos_app • ClockKit framework • – developer.apple.com/documentation/clockkit – Complications developer.apple.com/documentation/clockkit/adding_a_complication_to_your_watchos_app • HealthKit framework • – developer.apple.com/documentation/healthkit Mobile Application Development in iOS 32

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend