firebase-ios-sdk icon indicating copy to clipboard operation
firebase-ios-sdk copied to clipboard

[Firebase Database] Database calls do not work on watchOS 9

Open Rexios80 opened this issue 1 year ago • 47 comments

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


Rexios80 avatar Sep 09 '22 11:09 Rexios80

I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.

google-oss-bot avatar Sep 09 '22 11:09 google-oss-bot

Maybe related: https://github.com/pusher/NWWebSocket/issues/35

Rexios80 avatar Sep 11 '22 17:09 Rexios80

To clarify, does RTDB work as expected on watchOS 8?

morganchen12 avatar Sep 12 '22 22:09 morganchen12

I've only been testing on watchOS 8 since I don't have a watchOS 9 device so yeah

Rexios80 avatar Sep 12 '22 22:09 Rexios80

My users on watchOS 9 informed me of the issue

Rexios80 avatar Sep 12 '22 22:09 Rexios80

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>}

sergey-g-s avatar Sep 13 '22 14:09 sergey-g-s

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 avatar Sep 13 '22 18:09 morganchen12

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.

ryanwilson avatar Sep 13 '22 20:09 ryanwilson

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?

Turacbey avatar Sep 14 '22 14:09 Turacbey

You can file feedback to Apple, or ask on the developer forums.

morganchen12 avatar Sep 14 '22 22:09 morganchen12

Someone posted this to the developer forums: https://developer.apple.com/forums/thread/714796

(thanks if it was someone from this thread!)

ryanwilson avatar Sep 15 '22 13:09 ryanwilson

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?

Rexios80 avatar Sep 15 '22 15:09 Rexios80

@rosalyntan, do you know the answer to this question?

morganchen12 avatar Sep 15 '22 18:09 morganchen12

I think I figured it out. Just add a header to the request like this:

"X-Firebase-AppCheck": appCheckToken

Rexios80 avatar Sep 15 '22 19:09 Rexios80

@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 avatar Sep 15 '22 19:09 weixifan

@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.

Rexios80 avatar Sep 15 '22 19:09 Rexios80

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...

Turacbey avatar Sep 16 '22 09:09 Turacbey

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 avatar Sep 16 '22 14:09 ryanwilson

@ryanwilson WebsocketTask was already half broken before watchOS 9

Rexios80 avatar Sep 16 '22 15:09 Rexios80

Here's one using NWConnection: https://github.com/Rexios80/watchos_nwwebsocket_test

Rexios80 avatar Sep 16 '22 15:09 Rexios80

On the Developer forum, why no one answer our question?

Turacbey avatar Sep 16 '22 18:09 Turacbey

Uhhh... WHAT???

IMG_1178

Rexios80 avatar Sep 17 '22 01:09 Rexios80

Here's the linked thread: https://developer.apple.com/forums/thread/127232

Rexios80 avatar Sep 17 '22 01:09 Rexios80

Oh also there's this so don't feel crazy for thinking it was supported this whole time.

Screen Shot 2022-09-16 at 9 25 37 PM

Rexios80 avatar Sep 17 '22 01:09 Rexios80

Looks like everyone is shocked 😧

Turacbey avatar Sep 19 '22 20:09 Turacbey

Any updates?

sergey-g-s avatar Sep 21 '22 14:09 sergey-g-s

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. 😢

mortenbekditlevsen avatar Sep 21 '22 19:09 mortenbekditlevsen

My team and I are experiencing this issue also.

ghost avatar Sep 24 '22 12:09 ghost

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!

yeniel avatar Sep 27 '22 11:09 yeniel