Apple Watch: Can one Watchkit App communicate with more than one iOS App?

时间:2015-06-25 19:09:27

标签: ios iphone watchkit apple-watch

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 个答案:

答案 0 :(得分:2)

事实上,watchOS应用程序已链接到iOS配套应用程序。

在这两个版本中,每个watchOS应用程序都有两个目标:WatchKit App - 包含故事板,图标等 - 以及WatchKit扩展,其中包含代码。

在watchOS 1(旧WatchKit)+ iOS 8组合中,WatchKit App安装在Apple Watch上,WatchKit Extension和iOS应用程序都安装在用户的iPhone上。

另外,在watchOS 2 + iOS 9组合中,WatchKit App和WatchKit Extension都安装在用户的Apple Watch上,iOS App是iPhone上安装的唯一代码和视图。

运行iOS应用程序只需要一个目标,因此它可以在没有Apple Watch的情况下运行(自第一个iPhone OS以来)。

但运行watchOS应用程序需要WatchKit App和WatchKit Extension。在watchOS 1(旧的WatchKit)中,因为一个在iPhone上,而另一个在Apple Watch上,所以运行的应用程序需要用蓝牙连接它们,所以你必须在附近携带你的iPhone。在watchOS 2中,两者都在Apple Watch上,因此正在运行的应用程序不需要连接到iPhone并且附近有iPhone。您可以将它们与watchOS 2 SDK(在Xcode 7中)中包含的WatchConnectivity框架连接起来。

因此在watchOS 2应用程序可以独立运行,但它们根本不是独立的。在iPhone上安装时,它们会安装在Apple Watch上,并且可以相互连接。创建新的watchOS应用程序时,在将其提交到iTunes Connect时,必须将其与iPhone应用程序一起包含。

注意:这使watchOS应用程序更加快速可靠。

因此,在这两个版本中,每个WatchKit应用都与一个扩展和一个iOS应用相关联,因此您无法将一个watchOS应用链接到多个iPhone应用,或将iOS应用链接到多个WatchKit目标。 (例外情况是为watchOS 1(旧WatchKit)和watchOS 2制作两个目标(它们都是一个应用程序,但在两个不同版本的手表操作系统中)。

总之,您无法将多个watchOS应用或多个iOS应用链接在一起。这就是watchOS 1& 2,将来可能会改变。

答案 1 :(得分:2)

你可以做到这一点。

但仅在两个iOS应用程序均由同一开发人员开发的情况下。

可行的方法是将所有三个应用程序放在同一个应用程序组中。 这将允许所有三个应用程序访问一个公共存储,在那里他们可以存储他们的信息以供其他应用程序访问。

此功能用于iOS App< - >在Watch OS 1中观看App通信,并与今天的扩展进行通信。

您可以在此处找到使用App Groups的教程: http://www.codingexplorer.com/share-data-in-your-swift-watchkit-apps-with-app-groups/