6

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?

Dávid Pásztor
  • 51,403
  • 9
  • 85
  • 116
Hoovin Shmoovin
  • 161
  • 2
  • 13
  • See https://groups.google.com/forum/#!topic/firebase-talk/QZ3X9JLjDwk and https://stackoverflow.com/questions/38635082/new-firebase-with-watch-os2-3 – Frank van Puffelen Aug 03 '17 at 03:26
  • I've created firebase feature request for that: https://github.com/firebase/firebase-ios-sdk/issues/4556 – Alex Dec 27 '19 at 14:03

2 Answers2

15

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:

  1. Use the Firebase REST API directly from your watch app.
  2. 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.

Dávid Pásztor
  • 51,403
  • 9
  • 85
  • 116
  • @tymac the watch doesn't need to have direct internet access to be able to make network calls from your WatchKit Extension. The phone tethers its cellular connection to the watch in case of cellular connection, otherwise the watch can directly connect to the same wifi the phone is on. So my recommendation is still to use the REST API. Sadly the use of WatchConnectivity places a lot of restrictions on the watch app (it can only get data from the phone when the phone app is running). Don't rely on what FB Messenger is doing, that's one of the worst watch apps. It wasn't working at all for months – Dávid Pásztor Mar 17 '19 at 22:21
  • @tymac so many people are using it, because there are certain tasks that can only be solved on the phone, so if you need to share data from those, you need to transfer it to the watch somehow. Moreover, a lot of companies still use legacy codebases and haven't updated their watchOS apps to do the networking in the watchOS extension (sadly watchOS is the last priority for most companies). I can't really answer the questions about the models or notifications without more context, so you're better off asking separate specific questions as you said. – Dávid Pásztor Mar 18 '19 at 00:10
  • 1
    You said `there are certain tasks that can only be solved on the phone...` For example? What would be these situations in a chat app that would require WC? – Edison Mar 18 '19 at 06:48
  • @DávidPásztor: Is there any support now for WatchOs 6 push notifications of firebase? – huzefa biyawarwala Mar 08 '20 at 08:20
  • 2
    @huzefabiyawarwala please check [this](https://github.com/firebase/firebase-ios-sdk/issues/269) link for specific Firebase features on watchOS – Dávid Pásztor Mar 09 '20 at 10:05
0

Firebase v7.9.0 added WatchOS support for realtime database.

https://firebase.google.com/support/release-notes/ios#realtime-database

Rohit Rajendran
  • 629
  • 9
  • 27