transistorsoft / react-native-background-fetch

Periodic callbacks in the background for both IOS and Android
MIT License
1.43k stars 191 forks source link

How to run a function in background & foreground for IOS using react-native-background-fetch when app is closed #450

Closed xts-bit closed 11 months ago

xts-bit commented 11 months ago

How to run a function in the background & foreground for IOS using react-native-background-fetch when the app is closed? I am trying to use this package to upload image to the cloud however it takes time to upload the image to the cloud so how can i use this package to do that?

Can anyone give me a code example for doing that with React native cli apps? i tried myself but it does not work on the app is closed

christocracy commented 11 months ago

for IOS using react-native-background-fetch when the app is closed

You can’t. iOS does not fire fetch events when the user terminates the app.

there is no such thing as stopOnTerminate: false for iOS. This is a decision by Apple and there’s no way around it.

only Android allows fetch events to Continue when the user terminated the app.

xts-bit commented 11 months ago

@christocracy Can you please make me clear Chirs What do you mean "iOS does not fire fetch events when the user terminates the app."

Let me tell me first what exactly is not working "first i press the upload button and quickly go my iPhone home screen swipe up and again swipe up the app"

christocracy commented 11 months ago

"first i press the upload button and quickly go my iPhone home screen swipe up and again swipe up the app"

That is known as “terminating the app”.

when you terminate your app, iOS no longer fires fetch events.

xts-bit commented 11 months ago

@christocracy Yeah I got you, I was on a trip to create my own package that work when the ios app was terminated but thank you for clearing things as Apple doesn't allow this,

By the way in my case if I run the function for uploading images to the cloud terminate the app and again open the app again will it automatically continue the uploading progress from there? or i need to start uploading the image from starting?