Writing the code
So, time to get some code written. We will start with some code that should look very familiar.
WatchConnectivity
Once again, we need to create a class that encapsulates all of the logic around communication with the outside world (or at least the part of the outside world that is squeezed into an iPhone).
WatchConnectivityManager class
In the project navigator, select the WatchConnectivity.swift
file. Delete the import Foundation
line from the code, and replace it with the following code:
import WatchConnectivity class WatchConnectivityManager: NSObject, WCSessionDelegate { static let sharedManager = WatchConnectivityManager() let dataManager = WatchDataManager.sharedManager private override init() { } func session(session: WCSession,didReceiveApplicationContext applicationContext: [String : AnyObject]) { } }
Don't be alarmed by the error warning that Xcode shows about the dataManager;
this is only happening because we haven't yet written the...