WatchOS2 Watch Connectivity still require app groups in capabilities? - ios

In the old WatchOS1, app groups was required for any sharing of data.
In WatchOS2, Watch Connectivity replaces the old framework for communication.
I was wondering if app groups is still needed?

No, app groups will not help with sharing data between your iOS app and the WatchKit extension. You might however need to use an app group between the WatchKit app and the WatchKit extension as some of the media playing APIs seem to run in the app process.

Related

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.

Using firebase with WatchKit

I am attempting to use the firebase database in my watchKit app. I have developed this feature on my iPhone application but have found it difficult to do the same on my Watch app. When I attempted to import firebase into the VC class in watch app, it is creating an error no such module 'firebase'.
Is it possible to use firebase inside a watch app?
Sadly there is no Firebase support for watchOS2 and watchOS3 due to the fact that there's no support for CFNetwork in these versions of watchOS and Firebase is highly dependent on this framework. Source (thanks for the link #FrankvanPuffelen in comments).
You have two alternatives:
Use the Firebase REST API directly from your watch app.
Handle all Firebase communication from the iPhone app and use the WatchConnectivity framework to send the relevant changes to your watch app.
Depending on your exact use case, you could choose any of the two. The main advantages/disadvantages of these two are that the WatchConnectivity framework is quite limited as in when it can be used. Both of your apps needs to be running at least in the background for the WatchConenctivity framework to work. On the other hand, if you choose to use the REST API, you don't need the watch app to communicate with the iPhone counterpart, the watch app can directly get the Firebase data using network requests. However, in this scenario, the network usage will be bigger, since you will need to essentially fetch the same information both for the iPhone and watch apps.
Update for watchOS 6:
Firebase Messaging has been released with watchOS support, however, the Realtime Database along with other Firebase SDKs are still not supported. You can track the progress of them in this GitHub issue, which also contains links to the specific feature request issues for the other SDKs.
Firebase v7.9.0 added WatchOS support for realtime database.
https://firebase.google.com/support/release-notes/ios#realtime-database

Why is my Apple Watch Simulator black?

I have a requirement to create a watchkit app.
Please let me know if it is possible to create a separate app with watch kit or do we have to do this with extensions.
I am testing my application in a simulator. The iPhone simulator and the Apple watch simulator both are coming up. The Apple watch simulator is black, no screen is coming up.
My System harddisk : 320 GB , RAM : 5 GB.
If you haven't read this already, have a look at it. In short it looks like you can only achieve this using extensions at the moment.
This article explains what they expect from you as a 3rd party watch app developer.
Apple Watch requires the presence of an iPhone to run third-party apps. To create a third-party app, you need two separate bundles: a WatchKit app (that runs on Apple Watch) and a WatchKit extension (that runs on the user’s iPhone). The WatchKit app contains only the storyboards and resource files associated with your app’s user interface. The WatchKit extension contains the code for managing the WatchKit app’s user interface and for responding to user interactions.
Also
Because a WatchKit app extends the behavior of your existing iOS app, the WatchKit app and WatchKit extension are bundled together and packaged inside your iOS app bundle. During installation of your iOS app, the system prompts the user to install the WatchKit app when a paired Apple Watch is present.
It's not possible to develop standalone WatchKit app. As you said - it has to be an extension. Also your iPhone app has to do something - it can not be just a container for your extension.
Watch Apps have to be set up as App extensions and cannot be created as stand-alone apps. This is just not what Apple has designed the Watch for, rather view it as an additional screen of your iOS device. Apple also recommends to have as much of your ressource-intensive code as possible in the main iOS-App - e.g. background tasks.
As to why your screen is black:
Make sure you are building the Watch App-Scheme. Then even if your Watch app does not have any UI elements yet, you should see the time in the upper right corner of the watch simulator.

WatchKit native applications

Is it possible to create native WatchKit applications, which would be able to run without an extension running on a paired iPhone ?
Not at the moment:
Apple Watch requires the presence of an iPhone to run third-party apps. To create a third-party app, you need two separate bundles: a WatchKit app (that runs on Apple Watch) and a WatchKit extension (that runs on the user’s iPhone). The WatchKit app contains only the storyboards and resource files associated with your app’s user interface. The WatchKit extension contains the code for managing the WatchKit app’s user interface and for responding to user interactions.
But it will come soon :
The iOS 8.2 SDK beta including WatchKit is available immediately for iOS Developer Program members at developer.apple.com/watchkit. The WatchKit site includes programming guides, human interface guidelines, templates and more. Starting later next year (meaning 2015), developers will be able to create fully native apps for Apple Watch.

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