Watchkit Connectivity Framework Vs App groups? - ios

I want to share data between watch and iphone application display it in glance view , which is the best way to share data Watch Connectivity framework or app groups ? If Watch Connectivity then which method in Watch connectivity is suitable for transfer data between glance view and iphone application?

App group will work only with a watchOS 1.0 app since the watch kit extension and the main iOS both run on the phone, since watchOS 2.0 the extension runs natively on the watch making app groups useless for data transfer since iOS and watchOS app runs on two different devices.
As Sam B pointed out in the comments since watchOS 2.0 the only way to transfer data between iOS and watchOS is the WatchConnectivity framework. This offers you three way to exchange data, is then up to you to choose the one that best fit your app:
updateApplicationContext:error: transfer a dictionary of data between phone and watch. This dictionary is seen like a state of your app and any new transfer will override previously sent ones, its useful if want to exchange background data. Your data is handled by the operating system and delivered when the receiver wakes up.
sendMessage:replyHandler:errorHandler:/sendMessageData:replyHandler:errorHandler: transfer respectively a dictionary and data (NSData) in real time (the receiver must be running), this is especially useful is game app.
transferUserInfo:/transferFile:metadata: transfer respectively a dictionary and a file in the background like method 1 but all transfers are delivered and not overwritten.
For further information you can read Apple Documentation or watch WWDC 2015 session 713.
About your last question method 2 doesn't fit your needs, maybe more 1 than 3, but that's up to you to decide, after watching the video I linked before you should have more clear ideas about what to choose.

WCSession is best way to communicate with ios application its also support background mode transfer from watch to application and application to watch
Link

Related

Sending data from apple watch to iPhone when iphone is not nearby using Swift

I am using Xcode 11.3.1. I wants to make an iOS and watchOS app using swift5. I understand we need to use WatchConnectivity class to send and receive data using message but, my concern is that how do we send data when Apple Watch is far from iphone. Assuming it's cellular and wifi both but still i need solution to get data from apple watch to iphone.
I wants to store those collected data from apple watch to iphone's local db by using realm.
It's only sendMessage(_:replyHandler:errorHandler:) and sendMessageData(_:replyHandler:errorHandler:) that require reachability, the other methods dequeue data once Apple Watch comes within range of the paired iPhone. If you need to transfer data while the devices are out of range and can depend on a watchOS network connection, look into the URL Loading System or CloudKit.

Have anyone worked on migrating an iOS app with Watch OS1 to Watch OS2 or higher versions which share data between iPhone & Watch

Have anyone worked on migrating an iOS app with Watch OS1 to Watch OS2 or higher versions. I have used Coredata & Appgroups for sharing data between iPhone app and watch app. Now in the newer Watch OS 2(& above) Apple no longer supports Appgroups to share data across iPhone app & Apple Watch app. Could you please help me in this.
I need to use Coredata to share data between the targets without having Appgroups.
Implement two-way communication between your Apple Watch app and the paired iPhone app with the Watch Connectivity framework.
Apple provided the sample code here
for connectivity between apple watch app and iphone app using latest OS version.
Apple OverView
Most Apple Watch apps require an exchange of data with a paired iPhone app. This sample demonstrates how to use the Watch Connectivity APIs to:
Update application contexts
Send messages
Transfer user info and manage the outstanding transfers
Transfer files, view transfer progress, and manage the outstanding
transfers
Update current complications from iOS apps
Handle Watch Connectivity background tasks
On watchOS 1, the watch app was an app extension that actually ran on the paired phone and the watch simply acted as a remote display. This is why it was possible to share data using an app group, just as you can with any other extension.
From watchOS 2.0 onwards the watch app executes on the watch itself so the watch app and the companion app no longer share a file system.
In fact, where possible, users should be able to use the watch app even when the watch isn't near the paired phone. This means that you need to adopt an asynchronous data sharing approach between the watch and phone apps
You will need to use the Watch Connectivity Framework for your app.

Possible to livestream hr data from watch app to iphone app? how if yes?

we have a iOS fitness application. We are building a watchOS companion app. We are looking for suggestions on how to architect the following feature.
We want to stream heart rate data back to our iOS app from our watchOS companion app. For example, during a HKworkout on the companion watchOS app, I would like to stream the users heartRate values back to the iOS app to be displayed during the users HKworkout session.
I am able to retrieve the hr data on the watch even if it is running in the background during a HKworkout, but don't know how to livestream the hr data back to the iOS app.
I tried to use TransferUserInfo function to send the data in the background, but it does not work properly. It has budget limitation as well.
Another idea is to use apple healthKit. In other word, send hr data from watchOS to the healthStore (healthKit) then simultaneously have the iOS app pull the data from healthKit. I figured there has to be an easier way to stream live HR data back to an iOS app.
Any ideas, thoughts, or suggestions would be greatly appreciated.
Thanks!
HealthKit isn't a realtime data transport mechanism for apps. If you want to transfer live information collected by your WatchKit app to the iPhone, you need to use WatchConnectivity APIs.
If WatchConnectivity APIs don't work reliably while your app is recording a workout, you should file a bug with Apple.

React-native native module possibilities for background task on IOS

My Problem: I have an app that communicates with a medical BLE device. I have it all working but my problem is that when an ios user puts the app in the background I stop getting/processing the messages sent via bluetooth. Android seems to keep getting these messages but from what I've found, on iOS, the JS bridge is torn down and there isn't a solution out there for this problem. The phone must continue to process the data sent from the BLE device.
My thought is this and this is my question for you all.
Would it be possible to create a native module for ios that will always be running and be doing the following: getting ble data as it is notified. Store that data to the file system and push it to a webservice all while the app is in the background? It would also be great to have the ability to read the fs created files and show some data about them when the app comes back to the foreground. Would this be possible?
Do you know of another option that could work?
Any help is greatly appreciated.
OK as I was heading down the native path and reading on the ios bluetooth schtuff I found this article Core Bluetooth Programming Guide and specifically it mentions a plist setting.
The Core Bluetooth background execution modes are declared by adding the UIBackgroundModes key to your Info.plist file and setting the key’s value to an array containing one of the following strings:
bluetooth-central —The app communicates with Bluetooth low energy peripherals using the Core Bluetooth framework.
bluetooth-peripheral —The app shares data using the Core Bluetooth framework.
So I thought to myself, would just by adding these keys to my xcode project that iOS would be smart enough and not care that I am a RN app and not native... well that was the ticket! I plugged these values in and the ble data is processed even when I open another app. "Wallah!" ;)
You have to enable iOS background mode capability in your Xcode project settings.
Also take a look at react-native-ble-plx which provides background support for both iOS and Android.

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

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 functions in the WatchKit app extension from the iPhone app?
If someone managed to do this, could he/she post an example? Thanks!
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
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.
In the following post is explained how to do it with default settings and you can also download the demo project.
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
You can see this library
https://github.com/mutualmobile/MMWormhole
It do Message passing between iOS apps and extensions.
looks like the links with brain.clear are not pointing to the right destination for ShinobiChart example
https://github.com/ShinobiControls/ChartWatch

Resources