react-native-background-upload
react-native-background-upload copied to clipboard
react-native-background-upload library does not upload files in background in iOS
Hi,
We are trying to use the latest version of react-native-background-upload and does not upload the files while the app is in background on iOS 14.0 . Works fine on Android. We tried using the example provided in this github repository. But that fails as well. XCode version used is 12.
Can someone help? Where are we going wrong?
Regards, Deepali
Hi, @deepalijagtap - solution stolen from https://github.com/cristianoccazinsp/react-native-background-upload#ios-background-events
By default, iOS does not wake up your app when uploads are done while your app is not in the foreground. To receive the upload events (error, completed...) while your app is in the background, add the following to your AppDelegate.m:
#import <VydiaRNFileUploader.h>
// required for background uploads
- (void)application:(UIApplication *)application
handleEventsForBackgroundURLSession:(NSString *)identifier
completionHandler:(void (^)(void))completionHandler {
[[VydiaRNFileUploader sharedInstance] setBackgroundSessionCompletionHandler:completionHandler];
}
This means you can do extra work in the background, like make network calls or uploads more files! You must call canSuspendIfBackground when you are done processing the events to sleep again. You can safely call this method when you are not in the background.
Thanks Mario! I wish this PR be merged to the master branch.
I wish the same
I'm getting a file not found error for VydiaRNFileUploader.h... any ideas?
Same here @elleryfamilia . Did you find a solution ?
Do we have to install something else ? I've installed the lib with npm i
and pod install
, which doesn't look to be a problem considering I'm able to use it without errors. I'm just not able to upload files on iOS while my app is in background, which is why I wanted to use the snippet of code above in AppDelegate.m
Thank you very much in advance to anyone who can help clarifying this 🙌🏼
@adrienfloor hm, I think it was just missing that file... I forked it and fixed it. Feel free to try my branch:
https://github.com/glancyinc/react-native-background-upload
You'll need to reference it in your package.json like so:
"react-native-background-upload": "github:glancyinc/react-native-background-upload",
Thank you very much @elleryfamilia , but this is iOS only right ? I still need the android part, any advice ? Thanks a lot.
I've tried this, I'm pretty sure it works but I would still have to do more tests. Let me know what you think : https://github.com/adrienfloor/react-native-background-upload Thanks for the help !
Even after adding those lines to the appDelegate.m does not help in background uploading, as when i switch to some other apps, the uploads get stuck where i left the app and restart every time i bring them back in foreground, can some one help?
Even after adding those lines to the appDelegate.m does not help in background uploading, as when i switch to some other apps, the uploads get stuck where i left the app and restart every time i bring them back in foreground, can some one help?
It's been working well for us. It's been so long since I touched this that i can't recall exactly. Did you try briefly pointing to my branch? If it works, i'll dig deeper into my changes and let you know
@adrienfloor @elleryfamilia Would you guys have a small test repo I could run? I tried using your versions, but still facing similar issues on ios 14.
I don't, sorry. Are you guys certain the uploads aren't happening? A few seconds after you background the app, your app will no longer receive notifications of progress. However, any code that you place in the completed event will get executed.
I'm using this plugin in combination with react-native-begin-background-task. react-native-begin-background-task will give your app an extra 20 seconds after the app is backgrounded to continue running code. Most of my uploads complete within those 20 seconds... however, many do go over and get handled 100% in the background by the background-upload lib.
@elleryfamilia You're right. With @adrienfloor's update (yours may work too, it is just the last one I tested) and by adding the code to the appDelegate.m, the progress stops but the completed function is called and executed in the future.
There seems to be some decision about when to upload done by the iPhone that I need to be aware of. Seems like it depend if the iPhone is charging or not, the battery saving mode on/off and probably other apps execution as well.
With the original library, there is 2 issues:
- The event does not seems to ever be called. Probably missing the update to appDelegate.m. The issues is that VydiaRNFileUploader.h is missing from the package entirely, so we cannot use that library.
- When coming back to the app, I constantly get the following error:
Lost connection to background transfer service
(Same as here: https://github.com/Vydia/react-native-background-upload/issues/92)
@adrienfloor how about doing PR with your branch? There is only a couple of new and small commits on top of yours and I think it could seriously help the community. Happy to do it for you if you do not have the time.
@adrienfloor There is a regression in your code. This commit got reverted: https://github.com/HomeskilletHealthInc/react-native-background-upload/commit/d5798e029c2f6a9bbc5a94aba1e3e8cc2d1f2074.
I forked your repo and added the commit above and fixed the upload > 100mb here: https://github.com/HomeskilletHealthInc/react-native-background-upload
Take a look if you got time, if not I'll keep testing a bit on my side and do a PR here next week.
Actually..... this commit is breaking the background upload: https://github.com/Vydia/react-native-background-upload/commit/d5798e029c2f6a9bbc5a94aba1e3e8cc2d1f2074
So it's either we have 100mb max upload with background upload or no background upload with unlimited file size.
If anyone has a solution, I'll take it!
Any update?
it's working in this repo but this repo didn't contain an android folder. https://github.com/cristianoccazinsp/react-native-background-upload
@filipef101 I'm using https://github.com/HomeskilletHealthInc/react-native-background-upload. This works for IOS, and the android code is untouched (it should be working).
The issue with ~100Mb upload limit is still present, but 100Mb on mobile is usually too large. I split the file into smaller chunks and do a multipart upload.
I'm sorry I haven't been following up here. I've had so much problem with RN and background upload for large files that I've been coding my whole app in React to be able the use it on the web without trouble, or at least for the uploading feature to work as expected.
@filipef101 I'm using https://github.com/HomeskilletHealthInc/react-native-background-upload. This works for IOS, and the android code is untouched (it should be working).
The issue with ~100Mb upload limit is still present, but 100Mb on mobile is usually too large. I split the file into smaller chunks and do a multipart upload.
can you please show the code.. how you chunk the file and then upload?
@Ameer-Muawiya I'll be glad to share, but the code is quite complicated and specifically made to upload to S3 directly. I don't have time to extract it and make it a smaller project that can run, so it would be pretty raw.
Let me know if you're interested.
Yes im really interested..i'll be very thankfull if u can share
On Thu, 14 Jul 2022, 11:18 pm Marc Simon, @.***> wrote:
@Ameer-Muawiya https://github.com/Ameer-Muawiya I'll be glad to share, but the code is quite complicated and specifically made to upload to S3 directly. I don't have time to extract it and make it a smaller project that can run, so it would be pretty raw.
Let me know if you're interested.
— Reply to this email directly, view it on GitHub https://github.com/Vydia/react-native-background-upload/issues/260#issuecomment-1184759287, or unsubscribe https://github.com/notifications/unsubscribe-auth/ASL4ILS5UPAWPVOKRI36MHDVUBKYNANCNFSM454LJJ7A . You are receiving this because you were mentioned.Message ID: @.***>
@Ameer-Muawiya You can find a gist for the uploadManager here: https://gist.github.com/msimon/b09da5ddcbc4fd98af7797c63a3fd1f0 And a gist for the uploadContext: https://gist.github.com/msimon/be11106eb53ad33e78b7dcd2997beda3
Most of the code is in uploadManager. You probably want to look at createMultiUploadTask, as this is the one that is cutting the file in smaller bit for upload.
Hope that helps
Awesome, thanks!
On Fri, 15 Jul 2022, 4:45 pm Marc Simon, @.***> wrote:
@Ameer-Muawiya https://github.com/Ameer-Muawiya You can find a gist for the uploadManager here: https://gist.github.com/msimon/b09da5ddcbc4fd98af7797c63a3fd1f0 And a gist for the uploadContext: https://gist.github.com/msimon/be11106eb53ad33e78b7dcd2997beda3
Most of the code is in uploadManager. You probably want to look at createMultiUploadTask, as this is the one that is cutting the file in smaller bit for upload.
Hope that helps
— Reply to this email directly, view it on GitHub https://github.com/Vydia/react-native-background-upload/issues/260#issuecomment-1185465606, or unsubscribe https://github.com/notifications/unsubscribe-auth/ASL4ILXRNLCJG5TP6RD4JWTVUFFOVANCNFSM454LJJ7A . You are receiving this because you were mentioned.Message ID: @.***>