Skip to content

Commit c01e158

Browse files
authored
Update README.md
1 parent 2cbc85b commit c01e158

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ A project committed to making file access and data transfer easier and more effi
2929
* [Multipart/form upload](#user-content-multipartform-data-example--post-form-data-with-file-and-data)
3030
* [Upload/Download progress](#user-content-uploaddownload-progress)
3131
* [Cancel HTTP request](#user-content-cancel-request)
32+
* [iOS Background Uploading](#user-content-ios-background-uploading)
3233
* [Android Media Scanner, and Download Manager Support](#user-content-android-media-scanner-and-download-manager-support)
3334
* [Self-Signed SSL Server](#user-content-self-signed-ssl-server)
3435
* [Transfer Encoding](#user-content-transfer-encoding)
@@ -475,6 +476,34 @@ If you have existing code that uses `whatwg-fetch`(the official **fetch**), it's
475476

476477
[See document and examples](https://github.com/joltup/rn-fetch-blob/wiki/Fetch-API#fetch-replacement)
477478

479+
### iOS Background Uploading
480+
Normally, iOS interrupts network connections when an app is moved to the background, and will throw an error 'Lost connection to background transfer service' when the app resumes. To continue the upload of large files even when the app is in the background, you will need to enable IOSUploadTask options.
481+
482+
First add the following property to your AppDelegate.h:
483+
```
484+
@property (nonatomic, copy) void(^backgroundTransferCompletionHandler)();
485+
```
486+
Then add the following to your AppDelegate.m:
487+
```
488+
- (void)application:(UIApplication *)application
489+
handleEventsForBackgroundURLSession:(NSString *)identifier
490+
completionHandler:(void (^)(void))completionHandler {
491+
self.backgroundTransferCompletionHandler = completionHandler;
492+
}
493+
```
494+
The following example shows how to upload a file in the background:
495+
```js
496+
RNFetchBlob
497+
.config({
498+
IOSBackgroundTask: true, // required for both upload
499+
IOSUploadTask: true, // Use instead of IOSDownloadTask if uploading
500+
uploadFilePath : 'file://' + filePath
501+
})
502+
.fetch('PUT', url, {
503+
'Content-Type': mediaType
504+
}, RNFetchBlob.wrap(filePath));
505+
```
506+
478507
### Android Media Scanner, and Download Manager Support
479508

480509
If you want to make a file in `External Storage` becomes visible in Picture, Downloads, or other built-in apps, you will have to use `Media Scanner` or `Download Manager`.

0 commit comments

Comments
 (0)