WatchConnectivity
We have done this so often now, we can almost do it blind.
Create a new Swift file, making sure that the WatchKit target is selected, and name it WatchConnectivity.swift
. Replace the import
statement with the following code, most of which you have seen before:
Import WatchConnectivity class WatchConnectivityManager: NSObject, WCSessionDelegate { static let sharedManager = WatchConnectivityManager() private override init() { super.init() if WCSession.isSupported() { let session = WCSession.defaultSession() session.delegate = self session.activateSession() } } func sendDataToWatch(data: AnyObject) { guard let contextData = data as? LocationSet else {return} let dataArray = contextDataFrom(locationSet: contextData) let context = [kApplicationContextDataKey: dataArray] do { try WCSession.defaultSession().updateApplicationContext(context) print("updateApplicationContext...