Browse Source

Update README.md

Guy Blank 6 years ago
parent
commit
c01e1588fd
No account linked to committer's email address
1 changed files with 29 additions and 0 deletions
  1. 29
    0
      README.md

+ 29
- 0
README.md View File

@@ -29,6 +29,7 @@ A project committed to making file access and data transfer easier and more effi
29 29
  * [Multipart/form upload](#user-content-multipartform-data-example--post-form-data-with-file-and-data)
30 30
  * [Upload/Download progress](#user-content-uploaddownload-progress)
31 31
  * [Cancel HTTP request](#user-content-cancel-request)
32
+ * [iOS Background Uploading](#user-content-ios-background-uploading)
32 33
  * [Android Media Scanner, and Download Manager Support](#user-content-android-media-scanner-and-download-manager-support)
33 34
  * [Self-Signed SSL Server](#user-content-self-signed-ssl-server)
34 35
  * [Transfer Encoding](#user-content-transfer-encoding)
@@ -475,6 +476,34 @@ If you have existing code that uses `whatwg-fetch`(the official **fetch**), it's
475 476
 
476 477
 [See document and examples](https://github.com/joltup/rn-fetch-blob/wiki/Fetch-API#fetch-replacement)
477 478
 
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
+
478 507
 ### Android Media Scanner, and Download Manager Support
479 508
 
480 509
 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`.