6

Steps to reproduce:

  1. Create a new app and call any API to the server to get data
  2. immediately take the app to background
  3. network get disconnects

below is the log:

2020-03-26 17:21:00.894598+0530 TestApp[783:152843] Connection 2: received failure notification

2020-03-26 17:21:00.895805+0530 TestApp[783:152843] Connection 2: failed to connect 1:53, reason -1

2020-03-26 17:21:00.895895+0530 TestApp[783:152843] Connection 2: encountered error(1:53)

2020-03-26 17:21:00.901375+0530 TestApp[783:152843] Task <36B9553A-99F2-42FE-8650-A5E5155EFCFD>.<1> HTTP load failed, 0/0 bytes (error code: -1005 [1:53])

2020-03-26 17:21:00.901831+0530 TestApp[783:152843] Connection 1: received failure notification

2020-03-26 17:21:00.902078+0530 TestApp[783:152843] [] nw_flow_add_write_request [C1.1 40.85.185.46:443 failed channel-flow (satisfied (Path is satisfied), interface: en0, ipv4, dns)] cannot accept write requests

2020-03-26 17:21:00.902200+0530 TestApp[783:152843] [] nw_write_request_report [C1] Send failed with error "Socket is not connected"

2020-03-26 17:21:00.905902+0530 TestApp[783:152870] Task <36B9553A-99F2-42FE-8650-A5E5155EFCFD>.<1> finished with error [-1005] Error Domain=NSURLErrorDomain Code=-1005 "The network connection was lost." UserInfo={NSUnderlyingError=0x2824734e0 {Error Domain=kCFErrorDomainCFNetwork Code=-1005 "(null)" UserInfo={_kCFStreamErrorCodeKey=53, _kCFStreamErrorDomainKey=1}}, NSErrorFailingURLStringKey=https://api.server.account, NSErrorFailingURLKey=https://api.server.account, _kCFStreamErrorDomainKey=1, _kCFStreamErrorCodeKey=53, NSLocalizedDescription=The network connection was lost.}

lreddy
  • 449
  • 6
  • 19
  • 1
    This is the expected behaviour. Network operations are interrupted when your app is suspended. You can use `beginBackgroundTask` to get some additional execution time, but this is tens of seconds, not minutes. – Paulw11 Mar 26 '20 at 13:12
  • @Paulw11 thanks. it would be helpful if you can share a sample code in Swift5. – lreddy Mar 30 '20 at 05:06
  • 1
    I face the same issue and found the solution in this post https://stackoverflow.com/a/40254595/10709673 – FoI2zFiiLM Jan 29 '21 at 03:57

0 Answers0