简体   繁体   中英

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.)

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.

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.

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.

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.


my info.plist files:

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
  • watchOS app is com.abc.myapp.watchkitapp
  • watchOS app extension is 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.

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.

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.

If you have "App is only available as a standalone watchOS app" in Info.plist, delete it even if it is false. Leave only "App can run independently of companion iPhone app". Also don't forget to set "WKCompanionAppBundleIdentifier" for Watch App (not extension). 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.

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). After the restart, everything seems to work fine.

This has happened only on Testflight builds so far. 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".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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