Skip to content
This repository was archived by the owner on Mar 16, 2019. It is now read-only.

Commit d477b1a

Browse files
committed
Add background session management #115
1 parent 42a4615 commit d477b1a

File tree

4 files changed

+11
-7
lines changed

4 files changed

+11
-7
lines changed

src/ios/RNFetchBlob/RNFetchBlob.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
@property (nonatomic) UIDocumentInteractionController * documentController;
2121

2222
+ (RCTBridge *)getRCTBridge;
23+
+ (void) checkExpiredSessions;
2324

2425
@end
2526

src/ios/RNFetchBlob/RNFetchBlob.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ - (id) init {
6161
[[NSFileManager defaultManager] createDirectoryAtPath:[RNFetchBlobFS getTempPath] withIntermediateDirectories:YES attributes:nil error:NULL];
6262
}
6363
bridgeRef = _bridge;
64-
[RNFetchBlobNetwork getExpiredTasks];
64+
[RNFetchBlobNetwork emitExpiredTasks];
6565
return self;
6666
}
6767

src/ios/RNFetchBlobNetwork.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
// Copyright © 2016 wkh237. All rights reserved.
77
//
88

9-
#ifndef RNFetchBlobResp_h
10-
#define RNFetchBlobResp_h
9+
#ifndef RNFetchBlobNetwork_h
10+
#define RNFetchBlobNetwork_h
1111

1212
#import <Foundation/Foundation.h>
1313
#import "RCTBridgeModule.h"
@@ -37,7 +37,7 @@ typedef void(^DataTaskCompletionHander) (NSData * _Nullable resp, NSURLResponse
3737
+ (void) cancelRequest:(NSString *)taskId;
3838
+ (void) enableProgressReport:(NSString *) taskId;
3939
+ (void) enableUploadProgress:(NSString *) taskId;
40-
+ (void) getExpiredTasks;
40+
+ (void) emitExpiredTasks;
4141

4242
- (nullable id) init;
4343
- (void) sendRequest;
@@ -50,4 +50,4 @@ typedef void(^DataTaskCompletionHander) (NSData * _Nullable resp, NSURLResponse
5050
@end
5151

5252

53-
#endif /* RNFetchBlobResp_h */
53+
#endif /* RNFetchBlobNetwork_h */

src/ios/RNFetchBlobNetwork.m

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ - (void) sendRequest:(__weak NSDictionary * _Nullable )options
217217

218218
// #115 handling task expired when application entering backgound for a long time
219219
[app beginBackgroundTaskWithName:taskId expirationHandler:^{
220-
NSLog([NSString stringWithFormat:@"session %@ expired event emit", taskId ]);
220+
NSLog([NSString stringWithFormat:@"session %@ expired", taskId ]);
221221
[expirationTable setObject:task forKey:taskId];
222222
[app endBackgroundTask:task];
223223

@@ -227,7 +227,7 @@ - (void) sendRequest:(__weak NSDictionary * _Nullable )options
227227
}
228228

229229
// #115 Invoke fetch.expire event on those expired requests so that the expired event can be handled
230-
+ (void) getExpiredTasks
230+
+ (void) emitExpiredTasks
231231
{
232232
NSEnumerator * emu = [expirationTable keyEnumerator];
233233
NSString * key;
@@ -238,6 +238,9 @@ + (void) getExpiredTasks
238238
NSData * args = @{ @"taskId": key };
239239
[bridge.eventDispatcher sendDeviceEventWithName:EVENT_EXPIRE body:args];
240240
}
241+
242+
// emit expired event once
243+
[expirationTable removeAllObjects];
241244
}
242245

243246
////////////////////////////////////////

0 commit comments

Comments
 (0)