I'm searching a way to know if I'm connected to in...
# ios
r
I'm searching a way to know if I'm connected to internet or not, any tips ? I tried 2 KMP libs, doesn't work, tried a iOS lib with
pod
, nothing.
m
We’re doing it manually here, it’s an okay amount of code to copy/paste
👍 1
m
which pod did you try?
r
I tried
Reachability
&`ReachabilitySwift` , and I tried kmp libs
Connectivity
&`ConnectivityStatus` . Thank's @mbonnin, I'll try !
l
Is this what you're looking for? https://github.com/jordond/connectivity
r
I tried this first, and it's stuck at
connectivity.status()
like it's waiting for something
l
Have you tried the statusUpdates version that gives a Flow?
r
Yes, nothing is emit too
l
@jordond, is it you?
j
There is a bug currently where it’s not emitting updates. I’m working on a fix, I’ve got a fix for the http artifact. Still working on the device artifact. @Raphael TEYSSANDIER Are you using the Compose artifact?
r
@jordond No the device one
l
@jordond The problem is that you're only registering for connectivity updates. There's also an asynchronous API to get the current connectivity, which you need to use just after you register for updates in your callbackFlow lambda.
You need to add it just after this line: https://github.com/jordond/connectivity/blob/4a2ab3f99f3561d1f4afe453c034348587805[…]ev/jordond/connectivity/internal/AndroidConnectivityProvider.kt And you also need to wrap it into a try block, then add
awaitCancellation()
, and in the finally block, you move the code you currently have in
awaitClose { … }
j
1.1.1 should be available from maven within the hour
👍 2