问题
I am developing a glance view for my Apple WatchOS2 app. I'am currently didn't fully understand the prequisites for a stable WatchConnectivity connection now. I have the strange situation, that in the simulator my ComplicationController could successfully a sendMessage Request. When I try to look at my glance, the sendMessage request failed with:
Error Domain=WCErrorDomain Code=7007
"WatchConnectivity session on paired device is not reachable."
UserInfo={NSLocalizedDescription=WatchConnectivity session
on paired device is not reachable.
I have to admit, that I didn't start my app on the simulator. But why could the ComplicationController communicate and the WatchController won't. And I found no explanation about the error 7007 on the internet.
override func awakeWithContext(context: AnyObject?) {
super.awakeWithContext(context)
WCSession.defaultSession().sendMessage(["request": "getGlancesImages" ], replyHandler: {
(result) -> Void in
self.processGetGlancesImages(result)
}, errorHandler: { NSLog("WatchGlanceController2. \($0.description)") } )
}
I am currently developing with WatchOS2 Beta 5 and iOS 9 Beta 5. I am fully aware, this is a beta but this is the last beta before release.
回答1:
Make sure the debugger is attached only to the Watch app and the iPhone app is run directly from the simulator.
So, run the iPhone app to have the latest code, then stop the execution.
Next, run the Watch app and open the iPhone simulator and open the iPhone app.
After both apps started (with the debugger attached only to the Watch app) the sendMessage:replyHandler:errorHandler:
's error callback should not be called and the message should send succesfully.
回答2:
Try to use
WCSession.defaultSession().reachable
in swift to check if it's reachable.
Objective C [WCSession.defaultSession] isReachable]
.
If it's return false/NO
choose Debug -> Attach to Process then find the application you want to attach then select it, should works.
来源:https://stackoverflow.com/questions/32409916/what-is-the-very-reason-for-watchkit2-error-code-7007-session-on-paired-device