How to establish a communication channel between Apple Watch Extension/App and iOS App

后端 未结 5 786
Happy的楠姐
Happy的楠姐 2021-02-09 05:26

I\'m exploring the WatchKit SDK.

When I have a WatchKit app, is it possible to set values (e.g. Text, settings) from the iPhone app on the WatchKit app? Can I call funct

相关标签:
5条回答
  • 2021-02-09 05:40

    You can see this library https://github.com/mutualmobile/MMWormhole

    It do Message passing between iOS apps and extensions.

    0 讨论(0)
  • 2021-02-09 05:41

    You can use App Group and sharedDefaults to share data between the WatchApp/Extension and the App on the phone. see example: WatchKit SDK not retrieving data from NSUserDefaults

    Study up on iOS8 Extension/App Groups/sharedDefaults and watchkit extension will make more sense.

    This sample takes a UIImage from Shinobi chart, save it to defaults as image. Then extension picks up the image through defaults and shows it on watch

    https://github.com/ChrisGrant/ChartWatch

    This one uses multipeer connectivity to have watch talk to phone.

    https://github.com/jsclayton/swatches

    but this uses Bluetooth and I presume the Watch OS also communicates to the phone using bluetooth so not sure if they'll both be allowed.

    We have no devices to test on yet so the /swatches app is just watch simuator talking to iphone simulator on same mac.

    If youve ever done low level AV programming you know the app may run on the simulator but fail on the device because the simulator can cheat an use Mac OSX media layer. May be the same for bluetooth.

    other samples

    https://github.com/search?q=WKInterfaceController&type=Code

    0 讨论(0)
  • 2021-02-09 05:41

    looks like the links with brain.clear are not pointing to the right destination for ShinobiChart example

    https://github.com/ShinobiControls/ChartWatch

    0 讨论(0)
  • 2021-02-09 05:51

    There are several solutions: CoreData, NSKeyedUnarchiver and NSUserDefaults. With a common background for sharing the common data resource (Database, file or user default settings), this is enabling App Groups capabilities on both targets project properties.

    enter image description here

    In the following post is explained how to do it with default settings and you can also download the demo project.

    0 讨论(0)
  • 2021-02-09 05:57

    With watchOS2 now Apple supports Watch Connectivity Framework to pass information from watch extension to app and vice versa.

    Taken from Apple's docs

    Communicating with Your Companion iOS App

    The Watch Connectivity framework lets you create a bidirectional communications channel between your WatchKit extension and your companion iOS app. Use this channel to coordinate activities between the two processes. For example, you might use this framework to push updated information from your iOS app to your WatchKit extension. The framework provides options for transferring data in the background or while both apps are active and replaces the existing openParentApplication:reply: method of the WKInterfaceController class.

    For more information the classes of the Watch Connectivity framework, see Watch Connectivity Framework Reference.

    Taken from Apple's Developers Library

    0 讨论(0)
提交回复
热议问题