Xcode 真机调试 iWatch 的坑

非独立 watchOS 应用

总之而言,不要在 Xcode 上直接选择真机来运行 Watch App 工程。

由于 Watch App 不能从电脑直接安装,Xcode 需要首先把 swift 的运行时和一系列安装脚本先传到手机上,再由手机完成安装过程。之后 Xcode 还需要通过手机来和 Watch 建立连接才能调试。

这样的结果就是 Xcode 不停地提示正在连接手表以及正在重新连接手表。

最好的办法是,选择 iOS App,直接在 iPhone 上运行。

因为 iOS App 在安装的时候会把 Watch App 同样编译安装,之后只要手动在「手表」应用中重新安装 Watch App 即可。

独立 watchOS 应用

就别想了,通过 TestFlight 真机测试吧。

打包上传

WatchKit 2.0 app’s bundle ID person.bundle.Ropes.watchkitapp is not prefixed by the parent app’s bundle ID followed by a ‘.’; expected prefix

In the watch app info.plist, make sure the entry WKCompanionAppBundleIdentifier is present and that its value is the bundle ID of the iOS app.

另外,watchOS 应用的 bundle ID 后缀一定要加 .watch 或者 .watchkitapp

需要注意:

  • 如果是独立 watchOS 应用,那么只需要申请一份 Identifiers 和 Profiles,对应 Bundle ID。将该 Bundle ID 填入 iOS Target 的 Bundle Identifier 中,再将 Bundle ID.watch 或者 Bundle ID.watchkitapp 填入 watchOS Target 的 Bundle Identifier 中即可;
  • 如果不是独立 watchOS 应用,则需要申请两份 Identifiers 和 Profiles,对应 iOS Bundle IDiOS Bundle ID.watch(实测尾缀 .watchkitapp 无法申请 Identifiers)。再分别将 Identifiers 填入 iOS Target 与 watchOS Target 的 Bundle Identifier 即可。

网络的坑

Apple Watch App 网络权限问题

简单说,独立应用在 GPS 版本的手表上无法进行网络授权请求。只能是蜂窝版本;或者 iPhone&Apple Watch 同步开发,通过 iPhone 进行授权。


Xcode 真机调试 iWatch 的坑
https://wonderhoi.com/2024/01/19/Xcode-真机调试-iWatch-的坑/
作者
wonderhoi
发布于
2024年1月19日
许可协议