瀏覽代碼

Add background session management #115

Ben Hsieh 8 年之前
父節點
當前提交
d477b1a4cb

+ 1
- 0
src/ios/RNFetchBlob/RNFetchBlob.h 查看文件

@@ -20,6 +20,7 @@
20 20
 @property (nonatomic) UIDocumentInteractionController * documentController;
21 21
 
22 22
 + (RCTBridge *)getRCTBridge;
23
++ (void) checkExpiredSessions;
23 24
 
24 25
 @end
25 26
 

+ 1
- 1
src/ios/RNFetchBlob/RNFetchBlob.m 查看文件

@@ -61,7 +61,7 @@ RCT_EXPORT_MODULE();
61 61
         [[NSFileManager defaultManager] createDirectoryAtPath:[RNFetchBlobFS getTempPath] withIntermediateDirectories:YES attributes:nil error:NULL];
62 62
     }
63 63
     bridgeRef = _bridge;
64
-    [RNFetchBlobNetwork getExpiredTasks];
64
+    [RNFetchBlobNetwork emitExpiredTasks];
65 65
     return self;
66 66
 }
67 67
 

+ 4
- 4
src/ios/RNFetchBlobNetwork.h 查看文件

@@ -6,8 +6,8 @@
6 6
 //  Copyright © 2016 wkh237. All rights reserved.
7 7
 //
8 8
 
9
-#ifndef RNFetchBlobResp_h
10
-#define RNFetchBlobResp_h
9
+#ifndef RNFetchBlobNetwork_h
10
+#define RNFetchBlobNetwork_h
11 11
 
12 12
 #import <Foundation/Foundation.h>
13 13
 #import "RCTBridgeModule.h"
@@ -37,7 +37,7 @@ typedef void(^DataTaskCompletionHander) (NSData * _Nullable resp, NSURLResponse
37 37
 + (void) cancelRequest:(NSString *)taskId;
38 38
 + (void) enableProgressReport:(NSString *) taskId;
39 39
 + (void) enableUploadProgress:(NSString *) taskId;
40
-+ (void) getExpiredTasks;
40
++ (void) emitExpiredTasks;
41 41
 
42 42
 - (nullable id) init;
43 43
 - (void) sendRequest;
@@ -50,4 +50,4 @@ typedef void(^DataTaskCompletionHander) (NSData * _Nullable resp, NSURLResponse
50 50
 @end
51 51
 
52 52
 
53
-#endif /* RNFetchBlobResp_h */
53
+#endif /* RNFetchBlobNetwork_h */

+ 5
- 2
src/ios/RNFetchBlobNetwork.m 查看文件

@@ -217,7 +217,7 @@ NSOperationQueue *taskQueue;
217 217
 
218 218
     // #115 handling task expired when application entering backgound for a long time
219 219
     [app beginBackgroundTaskWithName:taskId expirationHandler:^{
220
-        NSLog([NSString stringWithFormat:@"session %@ expired event emit", taskId ]);
220
+        NSLog([NSString stringWithFormat:@"session %@ expired", taskId ]);
221 221
         [expirationTable setObject:task forKey:taskId];
222 222
         [app endBackgroundTask:task];
223 223
 
@@ -227,7 +227,7 @@ NSOperationQueue *taskQueue;
227 227
 }
228 228
 
229 229
 // #115 Invoke fetch.expire event on those expired requests so that the expired event can be handled
230
-+ (void) getExpiredTasks
230
++ (void) emitExpiredTasks
231 231
 {
232 232
     NSEnumerator * emu =  [expirationTable keyEnumerator];
233 233
     NSString * key;
@@ -238,6 +238,9 @@ NSOperationQueue *taskQueue;
238 238
         NSData * args = @{ @"taskId": key };
239 239
         [bridge.eventDispatcher sendDeviceEventWithName:EVENT_EXPIRE body:args];
240 240
     }
241
+    
242
+    // emit expired event once
243
+    [expirationTable removeAllObjects];
241 244
 }
242 245
 
243 246
 ////////////////////////////////////////