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

catch disabled Local Network case on iOS #241

@sultanmyrza

Description

@sultanmyrza

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions