firebase-ios-sdk
firebase-ios-sdk copied to clipboard
[Firebase Database] Database calls do not work on watchOS 9
Description
The FirebaseDatabase SDK does not work on watchOS 9. I have been having issues with websockets in my own products, and I believe this issue might be related to that. I am using FirebaseAuth just fine, and can make rest calls to the database with Alamofire.
Reproducing the issue
Try to read/write from the database on watchOS 9
Firebase SDK Version
9.5.0
Xcode Version
13.4.1
Installation Method
CocoaPods
Firebase Product(s)
Database
Targeted Platforms
watchOS
Relevant Log Output
Don't have physical access to a watchOS 9 device at the moment, and the issue doesn't show up on emulators.
If using Swift Package Manager, the project's Package.resolved
Expand Package.resolved
snippet
Replace this line with the contents of your Package.resolved.
If using CocoaPods, the project's Podfile.lock
Expand Podfile.lock
snippet
PODS:
- Alamofire (5.6.2)
- FirebaseAppCheck (9.5.0):
- FirebaseCore (~> 9.0)
- GoogleUtilities/Environment (~> 7.7)
- PromisesObjC (~> 2.1)
- FirebaseAuth (9.5.0):
- FirebaseCore (~> 9.0)
- GoogleUtilities/AppDelegateSwizzler (~> 7.7)
- GoogleUtilities/Environment (~> 7.7)
- GTMSessionFetcher/Core (< 3.0, >= 1.7)
- FirebaseCore (9.5.0):
- FirebaseCoreDiagnostics (~> 9.0)
- FirebaseCoreInternal (~> 9.0)
- GoogleUtilities/Environment (~> 7.7)
- GoogleUtilities/Logger (~> 7.7)
- FirebaseCoreDiagnostics (9.5.0):
- GoogleDataTransport (< 10.0.0, >= 9.1.4)
- GoogleUtilities/Environment (~> 7.7)
- GoogleUtilities/Logger (~> 7.7)
- nanopb (< 2.30910.0, >= 2.30908.0)
- FirebaseCoreInternal (9.5.0):
- "GoogleUtilities/NSData+zlib (~> 7.7)"
- FirebaseCrashlytics (9.5.0):
- FirebaseCore (~> 9.0)
- FirebaseInstallations (~> 9.0)
- GoogleDataTransport (< 10.0.0, >= 9.1.4)
- GoogleUtilities/Environment (~> 7.7)
- nanopb (< 2.30910.0, >= 2.30908.0)
- PromisesObjC (~> 2.1)
- FirebaseInstallations (9.5.0):
- FirebaseCore (~> 9.0)
- GoogleUtilities/Environment (~> 7.7)
- GoogleUtilities/UserDefaults (~> 7.7)
- PromisesObjC (~> 2.1)
- GoogleDataTransport (9.2.0):
- GoogleUtilities/Environment (~> 7.7)
- nanopb (< 2.30910.0, >= 2.30908.0)
- PromisesObjC (< 3.0, >= 1.2)
- GoogleUtilities/AppDelegateSwizzler (7.7.0):
- GoogleUtilities/Environment
- GoogleUtilities/Logger
- GoogleUtilities/Network
- GoogleUtilities/Environment (7.7.0):
- PromisesObjC (< 3.0, >= 1.2)
- GoogleUtilities/Logger (7.7.0):
- GoogleUtilities/Environment
- GoogleUtilities/Network (7.7.0):
- GoogleUtilities/Logger
- "GoogleUtilities/NSData+zlib"
- GoogleUtilities/Reachability
- "GoogleUtilities/NSData+zlib (7.7.0)"
- GoogleUtilities/Reachability (7.7.0):
- GoogleUtilities/Logger
- GoogleUtilities/UserDefaults (7.7.0):
- GoogleUtilities/Logger
- GTMSessionFetcher/Core (2.1.0)
- nanopb (2.30909.0):
- nanopb/decode (= 2.30909.0)
- nanopb/encode (= 2.30909.0)
- nanopb/decode (2.30909.0)
- nanopb/encode (2.30909.0)
- NWWebSocket (0.5.2)
- PromisesObjC (2.1.1)
- SwiftyStoreKit (0.16.1)
DEPENDENCIES:
- Alamofire
- FirebaseAppCheck
- FirebaseAuth
- FirebaseCore
- FirebaseCrashlytics
- NWWebSocket
- SwiftyStoreKit
SPEC REPOS:
trunk:
- Alamofire
- FirebaseAppCheck
- FirebaseAuth
- FirebaseCore
- FirebaseCoreDiagnostics
- FirebaseCoreInternal
- FirebaseCrashlytics
- FirebaseInstallations
- GoogleDataTransport
- GoogleUtilities
- GTMSessionFetcher
- nanopb
- NWWebSocket
- PromisesObjC
- SwiftyStoreKit
SPEC CHECKSUMS:
Alamofire: d368e1ff8a298e6dde360e35a3e68e6c610e7204
FirebaseAppCheck: 84e58ced2b43249bb75529da1c33193b71e9c3c6
FirebaseAuth: 741918f1fa62ed23246a509279f91d42d79a713f
FirebaseCore: 25c0400b670fd1e2f2104349cd3b5dcce8d9418f
FirebaseCoreDiagnostics: 17cbf4e72b1dbd64bfdc33d4b1f07bce4f16f1d8
FirebaseCoreInternal: 50a8e39cae8abf72d5145d07ea34c3244f70862b
FirebaseCrashlytics: d20fa38bb8c88cb0f1c9211286bc23ab58c1b464
FirebaseInstallations: 41f811b530c41dd90973d0174381cdb3fcb5e839
GoogleDataTransport: 1c8145da7117bd68bbbed00cf304edb6a24de00f
GoogleUtilities: e0913149f6b0625b553d70dae12b49fc62914fd1
GTMSessionFetcher: ffbb25ec00ebcb5201adab0a56d808f6f1902d9f
nanopb: b552cce312b6c8484180ef47159bc0f65a1f0431
NWWebSocket: 21f0c73639815da3272862c912275b26102aa80c
PromisesObjC: ab77feca74fa2823e7af4249b8326368e61014cb
SwiftyStoreKit: 6b9c08810269f030586dac1fae8e75871a82e84a
PODFILE CHECKSUM: bc259dea40d518c905f5b56c82dbfb8316383e71
COCOAPODS: 1.11.3
I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.
Maybe related: https://github.com/pusher/NWWebSocket/issues/35
To clarify, does RTDB work as expected on watchOS 8?
I've only been testing on watchOS 8 since I don't have a watchOS 9 device so yeah
My users on watchOS 9 informed me of the issue
Same issue :/
https://stackoverflow.com/questions/73701835/socket-connection-doesnt-work-on-watchos-9
Device Apple Watch 6 40mm
Platform WatchOS9
I have a similar problem using SwiftPhoenixClient
Here is all the information I get in the console
2022-09-13 17:22:04.194857+0300 Watch WatchKit Extension[375:22930] Connection 36: received failure notification
2022-09-13 17:22:04.194935+0300 Watch WatchKit Extension[375:22930] Connection 36: failed to connect 1:50, reason -1
2022-09-13 17:22:04.194950+0300 Watch WatchKit Extension[375:22930] Connection 36: encountered error(1:50)
2022-09-13 17:22:04.195691+0300 Watch WatchKit Extension[375:22930] Task <12FF0666-9653-4B03-A9C1-5D6BCC3DF419>.<1> HTTP load failed, 0/0 bytes (error code: -1009 [1:50])
2022-09-13 17:22:04.196176+0300 Watch WatchKit Extension[375:22930] Task <12FF0666-9653-4B03-A9C1-5D6BCC3DF419>.<1> finished with error [-1009] Error Domain=NSURLErrorDomain Code=-1009 "The internet connection appears to be offline." UserInfo={NSErrorFailingURLStringKey=websocket?vsn=2.0.0&signalingToken="1", NSErrorFailingURLKey=websocket?vsn=2.0.0&signalingToken="1", NSLocalizedDescription=The internet connection appears to be offline.., _NSURLErrorRelatedURLSessionTaskErrorKey=(
"LocalWebSocketTask <12FF0666-9653-4B03-A9C1-5D6BCC3DF419>.<1>"
), _NSURLErrorFailingURLSessionTaskErrorKey=LocalWebSocketTask <12FF0666-9653-4B03-A9C1-5D6BCC3DF419>.<1>}
CHAT ROOM: Socket Errored. Error Domain=NSURLErrorDomain Code=-1009 "Схоже, що немає інтернет-зʼєднання." UserInfo={NSErrorFailingURLStringKey=websocket?vsn=2.0.0&signalingToken="1", NSErrorFailingURLKey=websocket?vsn=2.0.0&signalingToken="1", NSLocalizedDescription=The internet connection appears to be offline., _NSURLErrorRelatedURLSessionTaskErrorKey=(
"LocalWebSocketTask <12FF0666-9653-4B03-A9C1-5D6BCC3DF419>.<1>"
), _NSURLErrorFailingURLSessionTaskErrorKey=LocalWebSocketTask <12FF0666-9653-4B03-A9C1-5D6BCC3DF419>.<1>}
Thanks all, this is NSURLErrorNotConnectedToInternet
, which I hope is an Apple bug. If NSURLSession socket support is removed in watchOS 9 we'll have to re-write the watchOS implementation of RTDB.
I just tested a plain websocket connection (not including RTDB) on my watchOS 9 device and it fails with the same error code. It does works in the simulator.
Thanks all, this is
NSURLErrorNotConnectedToInternet
, which I hope is an Apple bug. If NSURLSession socket support is removed in watchOS 9 we'll have to re-write the watchOS implementation of RTDB.
@morganchen12 How can we find out if socket support has been removed in watchOS 9?
You can file feedback to Apple, or ask on the developer forums.
Someone posted this to the developer forums: https://developer.apple.com/forums/thread/714796
(thanks if it was someone from this thread!)
While we're here... Does anyone know how to pass an App Check token with Firebase Database REST calls? I know you can pass an auth token with ?auth=
, but how do I also pass an App Check token?
@rosalyntan, do you know the answer to this question?
I think I figured it out. Just add a header to the request like this:
"X-Firebase-AppCheck": appCheckToken
@Rexios80 That is correct! If you are using Realtime Database with App Check and would like to manually make REST calls, please pass App Check tokens in the X-Firebase-AppCheck
header.
@weixifan Is this in the docs somewhere? The only way I figured this out is based on this page: https://firebase.google.com/docs/app-check/custom-resource-backend
That example doesn't explicitly state that Firebase services use that header themselves, but I took a lucky guess. This should be explicitly stated somewhere, probably in the REST API docs of services that have App Check available.
Someone posted this to the developer forums: https://developer.apple.com/forums/thread/714796
(thanks if it was someone from this thread!)
Guys, support the thread...
Someone posted this to the developer forums: https://developer.apple.com/forums/thread/714796 (thanks if it was someone from this thread!)
Guys, support the thread...
Posted, wanted to post a repro case for Apple folks to look at. That's here: https://gist.github.com/ryanwilson/fd5454a681eab32348ebc7119949182c
@ryanwilson WebsocketTask was already half broken before watchOS 9
Here's one using NWConnection: https://github.com/Rexios80/watchos_nwwebsocket_test
On the Developer forum, why no one answer our question?
Uhhh... WHAT???
Here's the linked thread: https://developer.apple.com/forums/thread/127232
Oh also there's this so don't feel crazy for thinking it was supported this whole time.

Looks like everyone is shocked 😧
Any updates?
It doesn't look very good:
https://developer.apple.com/forums/thread/715024
Basically it is stated that web sockets aren't supposed to be supported on watchOS. It just wasn't enforced correctly previously. 😢
My team and I are experiencing this issue also.
Hi, I'm also suffering this issue 😭 Because of that, I migrated the implementation of my ApiClient to API Rest calls to the Realtime Database. But requests take a long time, much longer than with the sdk in watchOS 8. I suppose that WebSocket are faster but how can I improve the API Rest calls? Should I implement a firebase function in the middle which make the request to the database and maybe implement a cache policy there?
Thanks in advance!