我正在制作一个独立的Apple Watch应用程序(但带有一个配套的iPhone应用程序,这对于手表应用程序来说不是必需的.)
I am making an independent Apple Watch app (but with a companion iPhone app which is not necessary for the watch app to function.)
如果安装了iPhone配套应用,则该应用将使用 WatchConnectivity 在设备之间同步数据.我可以在iOS应用程序上调用 session.updateApplicationContext(),并在Watch应用程序上接收 session(didReceiveApplicationContext).但是,走另一条路是不可能的.我总是收到7018的NSError代码,这意味着未安装iOS配套应用.
The app uses WatchConnectivity to sync data between devices if iPhone companion app is installed. I am able to call session.updateApplicationContext() on the iOS app and receive session(didReceiveApplicationContext) on the Watch app. 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.
我确保在模拟器中安装了watchOS和iOS应用程序(并在我的实际设备iPhone 11和Watch系列5上进行了测试.)但是从watchOS-> 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 6.0+ isCompanionAppInstalled 的新的 WCSession 实例变量.在我的手表应用程序上激活WCSession后,当我读取此变量时,该变量始终返回false.
I noticed there is a new WCSession instance variable available for watchOS 6.0+ isCompanionAppInstalled. When I read this variable after my WCSession is activated on my watch app, it always return false.
还有什么我需要注意的吗?我想也许在所有不同的info.plist中我做错了什么.但是我已经多次检查了它们.
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. But I have checked them multiple times.
我的info.plist文件:
my info.plist files:
在我的手表应用中:
WKWatchKitApp is YES WKCompanionAppBundleIdentifier is com.abc.myapp在我的手表扩展中:
App can run independently of companion iPhone app is YES NSExtension WKAppBundleIdentifier is com.abc.myapp.watchkitapp NSExtensionPointIdentifier is com.apple.watchkit
- iOS应用程序捆绑包标识符为com.abc.myapp
- watchOS应用为com.abc.myapp.watchkitapp
- 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.
推荐答案好.我找到了一种消除错误的方法,并使手表的连接功能从手表到iPhone.
Ok. I found a way to get rid of the error and have the watch connectivity work from watch to iPhone.
最初,我希望手表应用程序独立,因此在Xcode的手表扩展目标中,选中了支持在不安装iOS应用程序的情况下运行"复选框.但是,一旦我取消选中此框, WCSession.isCompanionAppInstalled 就会返回true,错误就会消失.从手表到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. But as soon as I uncheck this box, WCSession.isCompanionAppInstalled returns true and error goes away. Syncing from watch to iPhone starts working.
因此,希望这不是预期的行为,很快将被Apple修复. (我提交了一个错误报告.)但现在,我将不检查独立watchOS应用程序,因为在用户安装iPhone应用程序的情况下,我确实希望WatchConnectivity.
So hopefully this is not intended behavior and will soon be fixed by 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.
感谢您的阅读并祝您编程愉快.
Thank you for reading and good luck with your programming.
更多推荐
WatchOS应用未检测到同伴iOS应用
发布评论