简体   繁体   English

WatchOS 应用未检测到伴侣 iOS 应用

[英]WatchOS app not detecting companion iOS app

I am making an independent Apple Watch app (but with a companion iPhone app which is not necessary for the watch app to function.)我正在制作一个独立的 Apple Watch 应用程序(但有一个配套的 iPhone 应用程序,对于 function 的手表应用程序来说不是必需的。)

The app uses WatchConnectivity to sync data between devices if iPhone companion app is installed.如果安装了 iPhone 配套应用程序,该应用程序使用WatchConnectivity在设备之间同步数据。 I am able to call session.updateApplicationContext() on the iOS app and receive session(didReceiveApplicationContext) on the Watch app.我可以在 iOS 应用程序上调用session.updateApplicationContext()并在 Watch 应用程序上接收会话(didReceiveApplicationContext) But going the other way is not possible.但走另一条路是不可能的。 I always get an NSError code of 7018 which means the iOS companion app is not installed.我总是收到 7018 的 NSError 代码,这意味着未安装 iOS 配套应用程序。

I have made sure both watchOS and iOS app are installed in simulator (and tested on my actual devices, iPhone 11 & Watch series 5.) But getting the same failed results from watchOS -> iOS.我已确保 watchOS 和 iOS 应用程序都安装在模拟器中(并在我的实际设备 iPhone 11 和 Watch series 5 上进行了测试。)但是从 watchOS -> iOS 得到相同的失败结果。

I noticed there is a new WCSession instance variable available for watchOS 6.0+ isCompanionAppInstalled .我注意到有一个新的WCSession实例变量可用于 watchOS 6.0+ isCompanionAppInstalled When I read this variable after my WCSession is activated on my watch app, it always return false.当我在手表应用程序上激活我的 WCSession 后读取此变量时,它总是返回 false。

Is there anything else I need to look out for?还有什么我需要注意的吗? I am thinking maybe there is something I did wrong in all the different info.plist.我在想也许我在所有不同的 info.plist 中做错了什么。 But I have checked them multiple times.但我已经多次检查过它们。


my info.plist files:我的 info.plist 文件:

In my watch app:在我的手表应用程序中:

 WKWatchKitApp is YES
 WKCompanionAppBundleIdentifier is com.abc.myapp

In my watch extension:在我的手表扩展中:

  App can run independently of companion iPhone app is YES
  NSExtension
    WKAppBundleIdentifier is com.abc.myapp.watchkitapp
    NSExtensionPointIdentifier is com.apple.watchkit
  • iOS app bundle identifier is com.abc.myapp iOS 应用程序包标识符是 com.abc.myapp
  • watchOS app is com.abc.myapp.watchkitapp watchOS 应用程序是 com.abc.myapp.watchkitapp
  • watchOS app extension is com.abc.myapp.watchkitapp.watchkitextension watchOS 应用程序扩展名是 com.abc.myapp.watchkitapp.watchkitextension

Is there anything else I might be overlooking?还有什么我可能会忽略的吗?

Thank you very much for any help/insight you can offer into this.非常感谢您对此提供的任何帮助/见解。

Ok.好的。 I found a way to get rid of the error and have the watch connectivity work from watch to iPhone.我找到了一种消除错误的方法,并使手表与 iPhone 的手表连接正常工作。

Originally I wanted the watch app to be independent so in the watch extension target in Xcode, the check box "Supports Running Without iOS App Installation" is checked.最初我希望手表应用程序是独立的,所以在 Xcode 的手表扩展目标中,选中了“支持无需安装 iOS 应用程序即可运行”复选框。 But as soon as I uncheck this box, WCSession.isCompanionAppInstalled returns true and error goes away.但是一旦我取消选中此框, WCSession.isCompanionAppInstalled 就会返回 true 并且错误消失。 Syncing from watch to iPhone starts working.从手表同步到 iPhone 开始工作。

So hopefully this is not intended behavior and will soon be fixed by Apple.所以希望这不是预期的行为,很快就会被 Apple 修复。 (I filed a bug report.) But for now, I am just going to leave the independent watchOS app unchecked because I do want WatchConnectivity in case iPhone app is installed by user. (我提交了一个错误报告。)但现在,我将不选中独立的 watchOS 应用程序,因为我确实需要 WatchConnectivity,以防用户安装 iPhone 应用程序。

Thank you for reading and good luck with your programming.感谢您阅读并祝您编程愉快。

If you have "App is only available as a standalone watchOS app" in Info.plist, delete it even if it is false.如果您在 Info.plist 中有“App is only available as a standalone watchOS app”,即使它是 false 也将其删除。 Leave only "App can run independently of companion iPhone app".仅保留“应用程序可以独立于配套 iPhone 应用程序运行”。 Also don't forget to set "WKCompanionAppBundleIdentifier" for Watch App (not extension).另外不要忘记为 Watch App(不是扩展)设置“WKCompanionAppBundleIdentifier”。 At least it works on real device for me with these parameters.至少它可以在具有这些参数的真实设备上运行。

This seems to be a bug.这似乎是一个错误。 Sometimes when I start my WatchOS app, it gets WCSession.isCompanionAppInstalled = false all the time, even though the companion app on the iPhone is running, and other apps are able to communicate with the phone.有时,当我启动我的 WatchOS 应用程序时,它始终会WCSession.isCompanionAppInstalled = false ,即使 iPhone 上的配套应用程序正在运行,并且其他应用程序能够与手机通信。

This seems to go away when I force-restart the app on the watch (press side button, then swipe the app to the left and press the big red button, then start the app again).当我强制重启手表上的应用程序时,这似乎是 go(按下侧边按钮,然后向左滑动应用程序并按下大红色按钮,然后再次启动应用程序)。 After the restart, everything seems to work fine.重新启动后,一切似乎都正常。

This has happened only on Testflight builds so far.到目前为止,这仅发生在 Testflight 构建中。 If it happens in production builds, I'm going to file a bug.如果它发生在生产构建中,我将提交一个错误。

My iOS app will not launch in the Simulator if I uncheck "Supports Running Without iOS App Installation".如果我取消选中“Supports Running Without iOS App Installation”,我的 iOS 应用程序将不会在模拟器中启动。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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