0

I tried react native fetch and also with axios get and response from a server which may take a while to respond and pressed power key to put screen off. then power key pressed again to wake up mobile and unlocked and we have network error. this also happens when the screen automatically gets sleep while request in progress. I checked with android and this issue not exist with android. and even not with IOS emulators.

steps to reproduce:

  1. make a simple project with REST API call.
  2. add some delay from the server-side to above API.
  3. Run App on real device and call API.
  4. put screen off by press power key and unlock again.

now request will fail with a network error. is there any solution for this

Alireza
  • 2,319
  • 2
  • 23
  • 35
Russel
  • 29
  • 2
  • 7
  • You want to do some research into "background modes" on iOS, as they are relatively restricted. And things like [Finite-Length Tasks in background iOS swift](https://medium.com/@abhimuralidharan/finite-length-tasks-in-background-ios-swift-60f2db4fa01b); [Extending Your App's Background Execution Time](https://developer.apple.com/documentation/uikit/app_and_environment/scenes/preparing_your_ui_to_run_in_the_background/extending_your_app_s_background_execution_time); [How to use background task using Swift 3?](https://stackoverflow.com/questions/45192402/how-to-use-background-task-using-swift-3) – MadProgrammer Oct 28 '19 at 05:56
  • [How to use BackgroundTasks framework to keep your iOS app content up to date?](https://www.spaceotechnologies.com/ios-background-task-framework-app-update/); [How to run code when your app is terminated](https://www.hackingwithswift.com/example-code/system/how-to-run-code-when-your-app-is-terminated) might help some – MadProgrammer Oct 28 '19 at 05:56
  • i have enabled background modes already – Russel Oct 28 '19 at 06:05
  • Ok, are you using a background task? – MadProgrammer Oct 28 '19 at 07:07
  • no. just fetch on press button in react native. – Russel Oct 28 '19 at 10:11
  • Then, you should read through all those links to gain a better understanding of how you would create a background task which can continue to run after the app has been put to the background or suspended – MadProgrammer Oct 28 '19 at 21:28

0 Answers0