3
votes

I'd like to write a Watchkit App that can communicate with more than one iPhone App.

For example, let's call this Watchkit App, "PingPong." All it does is set up an observer, and respond to a request--similar to an ICMP ping request. So, when an App sends a "PING" to the watch, the PingPong Watchkit app responds with "PONG."

How can I make this functionality accessible to multiple apps? In other words, I would like to expose this very simple interface, so that different apps can use it.

Note that the docs state, "You must have an existing iOS app to create a WatchKit app. The WatchKit app is implemented as a separate target of your Xcode project and is built and packaged inside your iOS app’s bundle... Xcode configures the targets for your WatchKit app and WatchKit extension and adds the needed files to your iOS project. The bundle IDs for both new targets are configured automatically, based on the bundle ID of your iOS app. The base IDs for all three bundles must match; if you change your iOS app’s bundle ID, you must update the other bundle IDs accordingly." https://developer.apple.com/library/ios/documentation/General/Conceptual/WatchKitProgrammingGuide/ConfiguringYourXcodeProject.html#//apple_ref/doc/uid/TP40014969-CH2-SW1

This would imply that there's a 1-to-1 relationship between iOS extension apps and watchkit apps. Implication? Watchkit apps are essentially sandboxed, and this is not possible. But it couldn't hurt to ask. That's what SO is for, right? :P

Thx, Keith :)

2
I do not think, current state of watchkit development allows communication with more one ios app.casillas

2 Answers

2
votes

In fact, watchOS apps are linked to the iOS companion app.

In both versions, each watchOS app has two targets: WatchKit App - which contains storyboard, icons, etc - and WatchKit Extension, which contains the code.

In watchOS 1 (old WatchKit) + iOS 8 combination, WatchKit App is installed on Apple Watch, and both WatchKit Extension and iOS app are installed on user's iPhone.

In other way, in watchOS 2 + iOS 9 combination, both WatchKit App and WatchKit Extension are installed on user's Apple Watch, and iOS App is the only code and view installed on iPhone.

Running iOS app only requires one target, so it can run without Apple Watch (since the first iPhone OS).

But running watchOS apps needs both WatchKit App and WatchKit Extension. In watchOS 1 (the old WatchKit) because one is on iPhone and other on Apple Watch, so running apps need connecting between them with Bluetooth, so you have to carry your iPhone nearby. In watchOS 2, both are on Apple Watch, so running apps does not need connecting to iPhone and having iPhone nearby. You can connect them with WatchConnectivity framework included in watchOS 2 SDK (in Xcode 7).

So in watchOS 2 apps can run standalone, but they are not standalone at all. They install on Apple Watch when installing on iPhone, and they can connect with each other. When you create a new watchOS App, you must include it with your iPhone app when submitting it to the iTunes Connect.

NOTE: This makes watchOS apps more faster and reliable.

So in both versions, each WatchKit app is associated with one extension and one iOS app, so you can't link one watchOS app to more than one iPhone apps, or link an iOS app to more than one WatchKit targets. (The exception is in making two targets for watchOS 1 (old WatchKit) and watchOS 2 (which are both one app but in two different versions of the watch operating system).

In conclusion, you can't link multiple watchOS apps or multiple iOS apps together. That's the fact in watchOS 1 & 2 and may be changed in the future.

2
votes

You can achieve this.

BUT only in case both iOS apps are developed by the same developer.

The way to go would be to put all three apps in the same App Group. This would allow all three apps to access one common storage where they could store their information to be accessed by the other apps.

This functionality was used for iOS App <-> Watch App communication in Watch OS 1 and for communicating with today extensions.

You can find a tutorial to using App Groups here: http://www.codingexplorer.com/share-data-in-your-swift-watchkit-apps-with-app-groups/