15

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
doZer
  • 185
  • 1
  • 8

3 Answers3

22

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

Missing Watch app

Einzeln
  • 517
  • 4
  • 14
  • It worked for me. Everybody who struggles with that problem, check that solution. – Wojciech Konury Mar 22 '22 at 13:41
  • Thank you, I've been struggling with this for days – Chad Oct 08 '22 at 14:52
  • 1
    Worked for me as well. In addition to this, I needed to add the original apps bundle id into the WKCompanionAppBundleIdentifier key in the info tab, under my new watch app target build screen – Tomer Shemesh Oct 13 '22 at 16:27
  • 1
    I tried this solution but then getting following error while building the project "Cycle in dependencies between targets 'IOS_App' and 'Watch App'; building could produce unreliable results." – AVR Nov 30 '22 at 15:08
  • cycle error appears for me too – Mahdi Moqadasi Dec 14 '22 at 13:13
  • 1
    Also had to enter the WKCompanionAppBundleIdentifier in to Watch App > Info. The key was there but blank. Also my bundle identifiers in the watch app and widget were missing the prefix of the phones bundle identifier. Xcode gave decent errors though. – Rich Dec 30 '22 at 22:55
5

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 = WCSession.default
     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]) {
         //without 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)

Mahdi Moqadasi
  • 2,029
  • 4
  • 26
  • 52
4

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.

mskw
  • 10,063
  • 9
  • 42
  • 64