rn-fetch-blob
rn-fetch-blob copied to clipboard
how to download files in background for iOS ?? IOSBackgroundTask: true not work for me, any one please help me out ??
Hi ! Thank you for reporting an issue, but we would like to remind you, we have a trouble shooting page in our wiki. You may want to take a look on that page or find issues tagged "trouble shooting" :p
- please provide the version of installed library and RN project.
- a sample code snippet/repository is very helpful to spotting the problem.
- issues which have been tagged as 'needs feedback', will be closed after 2 weeks if receive no feedbacks.
- issues lack of detailed information will be closed without any feedback
@joltup
I am done with this https://github.com/Jacse/rn-fetch-blob#ios-background-uploading but still not working, please check if anyone has an idea @joltup
Thanks
Someone knows a library that works on background for ios?
Hi, I am also looking for IOS background upload support, here is my code RNFetchBlob.config({ IOSBackgroundTask: true, }) .fetch('POST', videoPath, { 'ClientToken': access_token, 'Content-Type' : 'application/octet-stream', }, RNFetchBlob.wrap(fileUrl)) .then((res) => { console.log('res',res.text()) }) .catch((err) => { console.log('err',err) })
while uploading data to server, if application is moved to background and again brining back to foreground RNFetchBlob callbacks are not getting called and showing loading continuously.
can anyone help me to fix this issue
Thanks
Hi, after adding the following code in AppDelegate, i am able to upload file in background
//AppDelegate.h
@property (nonatomic, assign) UIBackgroundTaskIdentifier taskIdentifier;
// AppDelegate.m
- (void)applicationWillResignActive:(UIApplication *)application {
if (self.taskIdentifier != UIBackgroundTaskInvalid) {
[application endBackgroundTask:self.taskIdentifier];
self.taskIdentifier = UIBackgroundTaskInvalid;
}
__weak typeof(self) weakSelf = self;
self.taskIdentifier = [application beginBackgroundTaskWithName:nil expirationHandler:^{
[application endBackgroundTask:weakSelf.taskIdentifier];
weakSelf.taskIdentifier = UIBackgroundTaskInvalid;
}];
}
here is my RNFetchBlob code
RNFetchBlob.config({ IOSBackgroundTask: true, }) .fetch('POST', videoPath, { 'ClientToken': access_token, 'Content-Type' : 'application/octet-stream', }, RNFetchBlob.wrap(fileUrl)) .then((res) => { console.log('res',res.text()) }) .catch((err) => { console.log('err',err) })
@venkataluri thanks it worked really. @mustafakemalelma
Hi, after adding the following code in AppDelegate, i am able to upload file in background
//AppDelegate.h @property (nonatomic, assign) UIBackgroundTaskIdentifier taskIdentifier; // AppDelegate.m - (void)applicationWillResignActive:(UIApplication *)application { if (self.taskIdentifier != UIBackgroundTaskInvalid) { [application endBackgroundTask:self.taskIdentifier]; self.taskIdentifier = UIBackgroundTaskInvalid; } __weak typeof(self) weakSelf = self; self.taskIdentifier = [application beginBackgroundTaskWithName:nil expirationHandler:^{ [application endBackgroundTask:weakSelf.taskIdentifier]; weakSelf.taskIdentifier = UIBackgroundTaskInvalid; }]; }
here is my RNFetchBlob code
RNFetchBlob.config({ IOSBackgroundTask: true, }) .fetch('POST', videoPath, { 'ClientToken': access_token, 'Content-Type' : 'application/octet-stream', }, RNFetchBlob.wrap(fileUrl)) .then((res) => { console.log('res',res.text()) }) .catch((err) => { console.log('err',err) })
Thanks, It worked for me!!!
Hi, after adding the following code in AppDelegate, i am able to upload file in background
//AppDelegate.h @property (nonatomic, assign) UIBackgroundTaskIdentifier taskIdentifier; // AppDelegate.m - (void)applicationWillResignActive:(UIApplication *)application { if (self.taskIdentifier != UIBackgroundTaskInvalid) { [application endBackgroundTask:self.taskIdentifier]; self.taskIdentifier = UIBackgroundTaskInvalid; } __weak typeof(self) weakSelf = self; self.taskIdentifier = [application beginBackgroundTaskWithName:nil expirationHandler:^{ [application endBackgroundTask:weakSelf.taskIdentifier]; weakSelf.taskIdentifier = UIBackgroundTaskInvalid; }]; }
here is my RNFetchBlob code
RNFetchBlob.config({ IOSBackgroundTask: true, }) .fetch('POST', videoPath, { 'ClientToken': access_token, 'Content-Type' : 'application/octet-stream', }, RNFetchBlob.wrap(fileUrl)) .then((res) => { console.log('res',res.text()) }) .catch((err) => { console.log('err',err) })
We are trying to download a video file in ios and got this error when the app went to background,
we have used the above code provided by @venkataluri , the download is working fine till 30 sec after that we are getting same issue, can someone help out here... we are stuck with this issue.
Someone knows a library that works on background for ios? npm i react-native-background-fetch try this one
It worked for me, but with a little of modifications in my AppDelegate.mm (note that for me it is not AppDelegate.m)
//AppDelegate.mm
- (void)applicationWillResignActive:(UIApplication *)application {
if (self.taskIdentifier != UIBackgroundTaskInvalid) {
[application endBackgroundTask:self.taskIdentifier];
self.taskIdentifier = UIBackgroundTaskInvalid;
}
__weak AppDelegate *weakSelf = self; //THIS LINE IS DIFFERENT
self.taskIdentifier = [application beginBackgroundTaskWithName:nil expirationHandler:^{
if (weakSelf) {
[application endBackgroundTask:weakSelf.taskIdentifier];
weakSelf.taskIdentifier = UIBackgroundTaskInvalid;
}
}];
}
When tried to build with npx react-native run-ios --simulator="iPhone 15 Pro" command, with the previous solution it was not able to compile, so had to modify it the above way to work!
Hi, after adding the following code in AppDelegate, i am able to upload file in background
//AppDelegate.h @property (nonatomic, assign) UIBackgroundTaskIdentifier taskIdentifier;
// AppDelegate.m
(void)applicationWillResignActive:(UIApplication *)application { if (self.taskIdentifier != UIBackgroundTaskInvalid) { [application endBackgroundTask:self.taskIdentifier]; self.taskIdentifier = UIBackgroundTaskInvalid; }
__weak typeof(self) weakSelf = self; self.taskIdentifier = [application beginBackgroundTaskWithName:nil expirationHandler:^{ [application endBackgroundTask:weakSelf.taskIdentifier]; weakSelf.taskIdentifier = UIBackgroundTaskInvalid; }]; } here is my RNFetchBlob code RNFetchBlob.config({ IOSBackgroundTask: true, }) .fetch('POST', videoPath, { 'ClientToken': access_token, 'Content-Type' : 'application/octet-stream', }, RNFetchBlob.wrap(fileUrl)) .then((res) => { console.log('res',res.text()) }) .catch((err) => { console.log('err',err) })
=> sometime, download file error still happend. Message error "The network connection was lost" when app running in background.
Hi, after adding the following code in AppDelegate, i am able to upload file in background //AppDelegate.h @Property (nonatomic, assign) UIBackgroundTaskIdentifier taskIdentifier; // AppDelegate.m
- (void)applicationWillResignActive:(UIApplication *)application { if (self.taskIdentifier != UIBackgroundTaskInvalid) { [application endBackgroundTask:self.taskIdentifier]; self.taskIdentifier = UIBackgroundTaskInvalid; } __weak typeof(self) weakSelf = self; self.taskIdentifier = [application beginBackgroundTaskWithName:nil expirationHandler:^{ [application endBackgroundTask:weakSelf.taskIdentifier]; weakSelf.taskIdentifier = UIBackgroundTaskInvalid; }]; } here is my RNFetchBlob code RNFetchBlob.config({ IOSBackgroundTask: true, }) .fetch('POST', videoPath, { 'ClientToken': access_token, 'Content-Type' : 'application/octet-stream', }, RNFetchBlob.wrap(fileUrl)) .then((res) => { console.log('res',res.text()) }) .catch((err) => { console.log('err',err) })
=> sometime, download file error still happend. Message error "The network connection was lost" when app running in background.
Have you found a solution?