简体   繁体   中英

WC WCSession counterpart app not installed

Making a connection between iOS and iWatch devices, xCode writes [WC] WCSession counterpart app not installed.

After a lot of research, I've found a solution, maybe it will be helpful for someone.

- Check your WatchKit Extention target. 
- Uncheck "Supports Running Without iOS App Installation"
- First run iwatch simulator, than run ios simulator with checkmark

It only worked for me by installing the Watch App from the watch settings app.

If I install the Watch App from xcode, the iOS app will give me the companion error message.

I have spent around 3-4 hr to fix this issue, it seems that somehow my Apple watch.app is missing from my Target > Frameworks so after clicking plus icon and adding it back, it doesn't report "WC WCSession counterpart app not installed" anymore

缺少手表应用

Finally, I made it. For anyone else, who has this problem:

  1. In iOS Target: Make sure in General>Frameworks, Libraries & Embedded Contents> Add YourWatchApp.app if it's not in the list. (For the loop problem, do the next step)

  2. In Watch Target: Go to BuildPhases>Copy Bundle Resources> and remove YouriOSApp.app from the list if exists.

  3. You must set delegate and activate it from both WatchApp and iOSApp as follows:

     self.session = session self.session.delegate = self self.session.activate()
  4. if you are using a helper class, Your class should implement NSObject as well:

     class ConnectivityHelper: NSObject, WCSessionDelegate {
  5. Make sure there is some seconds between calling activate method and sending message.

  6. If you are using a reply handler when sending message from Watch, Then you must implement didReceiveMessage method in iOS App which has replyHandler, else replyHandler on the watch returns an error and the iOS app won't receive the message.

  7. Check out this complete code that is working: iOS Part:

     import WatchConnectivity class PhoneConnectivity: NSObject { override init() { super.init() let session = WCSession.default session.delegate = self session.activate() } } extension PhoneConnectivity: WCSessionDelegate { //MARK: Delegate Methodes func session(_ session: WCSession, activationDidCompleteWith activationState: WCSessionActivationState, error: Error?) { } func sessionDidBecomeInactive(_ session: WCSession) { } func sessionDidDeactivate(_ session: WCSession) { } // Receiver func session(_ session: WCSession, didReceiveMessage message: [String: Any]) { //with reply handler } func session(_ session: WCSession, didReceiveMessage message: [String: Any], replyHandler: @escaping ([String: Any]) -> Void) { //with reply handler } // end Receiver }
  8. send message with a test string first like:

     WCSession.default.sendMessage(["TEST", "TEST2"], replyHandler: { dictionary in print(">WC> reply recieved: \(dictionary.first.,value)") }: errorHandler: { error in print(">WC> Error on sending Msg. \(error.localizedDescription)") })
  9. Most developers suggest that make session active ASAP (in iOS using didFinishLaunchingWithOptions in appDelegate of iOSApp & applicationDidFinishLaunching in WKExtensionDelegate of WatchApp)

如果上述解决方案对某人不起作用,您可以尝试从 iPhone 和 Watch 删除您的应用程序 - 对我有用。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM