Skip to content
This repository has been archived by the owner on Sep 26, 2022. It is now read-only.

catch disabled Local Network case on iOS #241

Open
sultanmyrza opened this issue Feb 28, 2022 · 3 comments
Open

catch disabled Local Network case on iOS #241

sultanmyrza opened this issue Feb 28, 2022 · 3 comments

Comments

@sultanmyrza
Copy link

In the iOS app, I use @capacitor-community/http to connect to an IoT device (in my case it's GoPro9). When I first connect to GoPro's WiFi Access Point and try to do get a request it was failing silently then I found out the problem was Local Network was disabled for my app (Settings -> MyApp -> Local Network).

When I do http request to GoPro and disable Local Network for my app, the native call ends up here

let task = urlSession.dataTask(with: urlRequest) { (data, response, error) in
  urlSession.invalidateAndCancel()
  if error != nil { <--- My call ends up here 
    return <--- But because of this return I can't catch on ionic side
  }

  let type = ResponseType(rawValue: responseType) ?? .default
  call.resolve(self.buildResponse(data, response as! HTTPURLResponse, responseType: type))
}

the error value is this

2022-02-28 16:10:54.342760+0800 App[1496:224988] Task <A4C6F12F-13CF-458C-9A21-D69F8DF46E36>.<2> finished with error [-1020] Error Domain=NSURLErrorDomain Code=-1020 "A data connection is not currently allowed." UserInfo={_kCFStreamErrorCodeKey=50, NSUnderlyingError=0x2819fe6a0 {Error Domain=kCFErrorDomainCFNetwork Code=-1020 "(null)" UserInfo={_NSURLErrorNWPathKey=unsatisfied (Local network prohibited), interface: en0, ipv4, _kCFStreamErrorCodeKey=50, _kCFStreamErrorDomainKey=1}}, _NSURLErrorFailingURLSessionTaskErrorKey=LocalDataTask <A4C6F12F-13CF-458C-9A21-D69F8DF46E36>.<2>, _NSURLErrorRelatedURLSessionTaskErrorKey=(
    "LocalDataTask <A4C6F12F-13CF-458C-9A21-D69F8DF46E36>.<2>"
), NSLocalizedDescription=A data connection is not currently allowed., NSErrorFailingURLStringKey=http://10.5.5.9:8080/gopro/media/list, NSErrorFailingURLKey=http://10.5.5.9:8080/gopro/media/list, _kCFStreamErrorDomainKey=1}
2022-02-28 16:10:54.342898+0800 App[1496:224988] [NSURLSession sharedSession] may not be invalidated
ERROR MESSAGE:  {"message":"Error","code":"REQUEST","errorMessage":"Error"}
@sultanmyrza
Copy link
Author

sultanmyrza commented Feb 28, 2022

I solved my issue with by call.reject()

if error != nil {
    call.reject("Error", "REQUEST", error, [:]) <--- just added this line
    return
}

@mrahn24
Copy link

mrahn24 commented Mar 1, 2022

Hi @sultanmyrza,

just want to let you know, that this is a duplicate of #224 and already resolved with #225. 😄

Have a great day!

@sultanmyrza
Copy link
Author

Hello @mrahn24
Oh, I see mrahn24@da0742f thank you for pointing that out. Then it can be closed now. Hope they will approve you PR soon 🤗

Thank you 🤗

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants