You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Thanks for this package! I'm trying to make use of it to detect if there is a network available in a sharing extension-- quickly after it starts. It's consistently just indicating there is no network connection. But, there is one. Is this expected behavior? Any thoughts?
I also see this behavior, but less consistently, when the app first launches-- and I quickly use this to detect network availability. It will at times incorrectly indicate the network is not available.
The text was updated successfully, but these errors were encountered:
Let me correct that. It's just not giving me an initial value early into the app launch. It's not that it's indicating that the network is not available.
Dear distant-past user @crspybits
I just had this exact same issue. I ended up using withTaskCancellationHandler to resolve this race condition. Here is a playground file to get you started - although I assume you're probably finished, published and subsetted this project by now
varstashedContinuations=[CheckedContinuation<Bool,Error>]()varlatestResult:ConnectivityResult?privatestructContinuation:Identifiable{letid=UUID()letcontinuation:CheckedContinuation<Bool,Error>}func hasInternetConnectivity()asyncthrows->Bool{
if let latestResult = latestResult {return latestResult.isConnected
}returntryawaitwithTaskCancellationHandler(
handler:{cancelStashedContinuations()},
operation:{tryawaitwithCheckedThrowingContinuation{ continuation in
stashedContinuations.append(.init(continuation: continuation))}})}func continueAllContinuations(){
stashedContinuations.forEach{
$0.continuation.resume(returning: latestResult?.isConnected == true)print(">> responding to a continuation!")}
stashedContinuations.removeAll()}func cancelStashedContinuations(){
stashedContinuations.forEach({ $0.continuation.resume(returning: false)})
stashedContinuations.removeAll()}Task{print("blah")DispatchQueue.main.asyncAfter(deadline:.now()+3){continueAllContinuations()}letconn=try?awaithasInternetConnectivity()print(conn)}
That was my draft POC (still need to thoroughly test when implemented). Hopefully its useful for future folk
Thanks for this package! I'm trying to make use of it to detect if there is a network available in a sharing extension-- quickly after it starts. It's consistently just indicating there is no network connection. But, there is one. Is this expected behavior? Any thoughts?
I also see this behavior, but less consistently, when the app first launches-- and I quickly use this to detect network availability. It will at times incorrectly indicate the network is not available.
The text was updated successfully, but these errors were encountered: