Browse Source

Add background session management #115

Ben Hsieh 8 years ago
parent
commit
d477b1a4cb

+ 1
- 0
src/ios/RNFetchBlob/RNFetchBlob.h View File

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

+ 1
- 1
src/ios/RNFetchBlob/RNFetchBlob.m View File

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

+ 4
- 4
src/ios/RNFetchBlobNetwork.h View File

6
 //  Copyright © 2016 wkh237. All rights reserved.
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
 #import <Foundation/Foundation.h>
12
 #import <Foundation/Foundation.h>
13
 #import "RCTBridgeModule.h"
13
 #import "RCTBridgeModule.h"
37
 + (void) cancelRequest:(NSString *)taskId;
37
 + (void) cancelRequest:(NSString *)taskId;
38
 + (void) enableProgressReport:(NSString *) taskId;
38
 + (void) enableProgressReport:(NSString *) taskId;
39
 + (void) enableUploadProgress:(NSString *) taskId;
39
 + (void) enableUploadProgress:(NSString *) taskId;
40
-+ (void) getExpiredTasks;
40
++ (void) emitExpiredTasks;
41
 
41
 
42
 - (nullable id) init;
42
 - (nullable id) init;
43
 - (void) sendRequest;
43
 - (void) sendRequest;
50
 @end
50
 @end
51
 
51
 
52
 
52
 
53
-#endif /* RNFetchBlobResp_h */
53
+#endif /* RNFetchBlobNetwork_h */

+ 5
- 2
src/ios/RNFetchBlobNetwork.m View File

217
 
217
 
218
     // #115 handling task expired when application entering backgound for a long time
218
     // #115 handling task expired when application entering backgound for a long time
219
     [app beginBackgroundTaskWithName:taskId expirationHandler:^{
219
     [app beginBackgroundTaskWithName:taskId expirationHandler:^{
220
-        NSLog([NSString stringWithFormat:@"session %@ expired event emit", taskId ]);
220
+        NSLog([NSString stringWithFormat:@"session %@ expired", taskId ]);
221
         [expirationTable setObject:task forKey:taskId];
221
         [expirationTable setObject:task forKey:taskId];
222
         [app endBackgroundTask:task];
222
         [app endBackgroundTask:task];
223
 
223
 
227
 }
227
 }
228
 
228
 
229
 // #115 Invoke fetch.expire event on those expired requests so that the expired event can be handled
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
     NSEnumerator * emu =  [expirationTable keyEnumerator];
232
     NSEnumerator * emu =  [expirationTable keyEnumerator];
233
     NSString * key;
233
     NSString * key;
238
         NSData * args = @{ @"taskId": key };
238
         NSData * args = @{ @"taskId": key };
239
         [bridge.eventDispatcher sendDeviceEventWithName:EVENT_EXPIRE body:args];
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
 ////////////////////////////////////////