Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

fetch in react-native gives error when App goes in background state in iOS Platform

static fetchCall(request) {
    console.log('Request' + JSON.stringify(request))
    return fetch(AsynCall.BASE_URL, {
      method: 'POST',
      body: JSON.stringify(request),
    }).
    then((response) => 
        response.json())
        .then((responseData) =>
            ResponseController.handleResponse(responseData),
        ).then(res => {
          return res
        })
        .catch((error) => {  
          throw (error)
        },
        )
  }
}

On Android its working fine in background, But iOS gives error in background.

"code": "ENSURLERRORDOMAIN-1005" , "message": "Network connection was lost"

Thanks in Advance.

like image 444
Imanshu Avatar asked Sep 01 '25 20:09

Imanshu


1 Answers

That's because react-native doesn't support background tasks out of the box. Consider using a third-party library, like react-native-background-fetch.

like image 87
E. Dn Avatar answered Sep 03 '25 11:09

E. Dn