WC WCSession对应的应用未安装。

16

在iOS和iWatch设备之间建立连接时,xCode会写下[WC] WCSession 对应的应用未安装。

经过大量研究,我找到了一个解决方案,希望对某些人有所帮助。

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

1
我有同样的问题,但以上方法没有解决。 - Rinto Andrews
我正在使用 Xcode 12,Xcode 12 是否存在任何问题? - Rinto Andrews
3个回答

23

我花了大约3-4个小时来解决这个问题,看起来我的Apple watch.app从我的Target > Frameworks中不见了,所以在点击加号图标并将其添加回去后,它不再报告“WC WCSession对应的应用程序未安装”

Missing Watch app


它对我有效。每个遇到这个问题的人,请检查那个解决方案。 - Wojciech Konury
谢谢,我已经为此苦苦挣扎了好几天。 - Chad
1
对我也起作用了。除此之外,我还需要在信息选项卡下的新手表应用程序构建屏幕中将原始应用程序包标识符添加到WKCompanionAppBundleIdentifier键中。 - Tomer Shemesh
1
我尝试了这个解决方案,但在构建项目时遇到以下错误:“目标‘IOS_App’和‘Watch App’之间存在依赖循环;构建可能会产生不可靠的结果。” - AVR
我也遇到了循环错误。 - Mahdi Moqadasi
1
还必须在手表应用程序>信息中输入WKCompanionAppBundleIdentifier。该键存在但为空。此外,手表应用程序和小部件中的捆绑标识符缺少电话捆绑标识符的前缀。Xcode 给出了不错的错误提示。 - Rich

5

终于搞定了。对于其他也遇到此问题的人:

  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)


4

只有在从手表设置应用程序中安装手表应用程序时,它才对我起作用。

如果我从Xcode安装手表应用程序,则iOS应用程序会给我伴侣错误消息。


2
谢谢,谢谢,谢谢!经过一天的尝试,我终于收到了我的第一条WCSession消息! :) - Tomáš Kafka
5
我的手表应用程序在“设置”应用程序中没有出现,有什么想法吗? - oskarko
你应该在iOS目标框架中添加watchApp。关于修复循环错误和一些建议,请查看我的答案。 - Mahdi Moqadasi
是的,这是最好的答案,它真的很有效,谢谢你。只不过我是通过手机而不是手表来完成的,使用了手机上的手表应用程序,但还是非常感谢,太棒了。 - Ahmed El-Bermawy

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接