I think I've got my Connectivity stuff set up properly, was going off the Lister sample app. But, every time I try to send stuff via WCSession, it fails. Here's the code:
// iOS App, in my ViewController
override func viewDidLoad() {
super.viewDidLoad()
if WCSession.isSupported() {
WCSession.defaultSession().delegate = self
WCSession.defaultSession().activateSession()
}
}
func session(session: WCSession, didReceiveMessage message: [String : AnyObject]) {
let msg = message["message"] as! String
print("Got message! \(msg)")
}
// --------------
// WatchKit Extension - WKInterfaceController subclass
@IBAction func buttonTapped() {
let session = WCSession.defaultSession()
print("Session is reachable: \(session.reachable)") // this is false
let msg = ["message": "derp derp derp"]
session.sendMessage(msg, replyHandler: { reply in
print("Got reply: \(reply)")
}, errorHandler: { error in
print("error: \(error)")
})
}
The error in the errorHandler reads "Error Domain=WCErrorDomain Code=7004 "The operation couldn’t be completed. (WCErrorDomain error 7004.)"
My suspicion is that I don't have the simulators properly running at the same time. I am running them via the "WatchKit App" scheme in the "iPhone 6 + 38mm" simulators. The watch simulator starts the app, but the iPhone simulator does not.
I'm still new to watchOS dev, so not sure if there's another step.
I found the answer in session 108 - Building Watch Apps, roughly 30 minutes in.
- Run the app with the Phone + Simulator scheme. This will start the watch sim.
- Switch the scheme to the Phone scheme associated with it (so, if you were using iPhone 6 + 38mm Watch, use iPhone 6)
- Hold down control and click the run button. This will run the scheme without rebuilding (and stopping the watch sim).
Now you'll have both running at the same time. I've noticed that sometimes on step 3, the watch app will go to the home screen. It's still running though, start it back up and Connectivity will still work.