Skip to content

Commit f6fae9b

Browse files
author
Artur Chrusciel
committed
Merge branch 'synchronized' into exception_fixes
2 parents 17cc8b0 + 57102f4 commit f6fae9b

11 files changed

+651
-621
lines changed

ios/RNFetchBlob.xcodeproj/project.pbxproj

+7-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
objects = {
88

99
/* Begin PBXBuildFile section */
10+
8C4801A6200CF71700FED7ED /* RNFetchBlobRequest.m in Sources */ = {isa = PBXBuildFile; fileRef = 8C4801A5200CF71700FED7ED /* RNFetchBlobRequest.m */; };
1011
A158F4271D052E49006FFD38 /* RNFetchBlobFS.m in Sources */ = {isa = PBXBuildFile; fileRef = A158F4261D052E49006FFD38 /* RNFetchBlobFS.m */; };
1112
A158F42D1D0535BB006FFD38 /* RNFetchBlobConst.m in Sources */ = {isa = PBXBuildFile; fileRef = A158F42C1D0535BB006FFD38 /* RNFetchBlobConst.m */; };
1213
A158F4301D0539DB006FFD38 /* RNFetchBlobNetwork.m in Sources */ = {isa = PBXBuildFile; fileRef = A158F42F1D0539DB006FFD38 /* RNFetchBlobNetwork.m */; };
@@ -29,6 +30,8 @@
2930
/* End PBXCopyFilesBuildPhase section */
3031

3132
/* Begin PBXFileReference section */
33+
8C4801A4200CF71700FED7ED /* RNFetchBlobRequest.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RNFetchBlobRequest.h; sourceTree = "<group>"; };
34+
8C4801A5200CF71700FED7ED /* RNFetchBlobRequest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RNFetchBlobRequest.m; sourceTree = "<group>"; };
3235
A158F4261D052E49006FFD38 /* RNFetchBlobFS.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RNFetchBlobFS.m; sourceTree = "<group>"; };
3336
A158F4281D052E57006FFD38 /* RNFetchBlobFS.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RNFetchBlobFS.h; sourceTree = "<group>"; };
3437
A158F4291D0534A9006FFD38 /* RNFetchBlobConst.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RNFetchBlobConst.h; sourceTree = "<group>"; };
@@ -71,8 +74,10 @@
7174
A1F950181D7E9134002A95A6 /* IOS7Polyfill.h */,
7275
A1AAE2981D300E4D0051D11C /* RNFetchBlobReqBuilder.m */,
7376
A1AAE2971D300E3E0051D11C /* RNFetchBlobReqBuilder.h */,
74-
A158F42F1D0539DB006FFD38 /* RNFetchBlobNetwork.m */,
7577
A158F42E1D0539CE006FFD38 /* RNFetchBlobNetwork.h */,
78+
A158F42F1D0539DB006FFD38 /* RNFetchBlobNetwork.m */,
79+
8C4801A4200CF71700FED7ED /* RNFetchBlobRequest.h */,
80+
8C4801A5200CF71700FED7ED /* RNFetchBlobRequest.m */,
7681
A158F42C1D0535BB006FFD38 /* RNFetchBlobConst.m */,
7782
A158F4291D0534A9006FFD38 /* RNFetchBlobConst.h */,
7883
A158F4281D052E57006FFD38 /* RNFetchBlobFS.h */,
@@ -149,6 +154,7 @@
149154
buildActionMask = 2147483647;
150155
files = (
151156
A166D1AA1CE0647A00273590 /* RNFetchBlob.h in Sources */,
157+
8C4801A6200CF71700FED7ED /* RNFetchBlobRequest.m in Sources */,
152158
A158F42D1D0535BB006FFD38 /* RNFetchBlobConst.m in Sources */,
153159
A158F4271D052E49006FFD38 /* RNFetchBlobFS.m in Sources */,
154160
A158F4301D0539DB006FFD38 /* RNFetchBlobNetwork.m in Sources */,

ios/RNFetchBlob/RNFetchBlob.h

-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
@property (retain) UIDocumentInteractionController * documentController;
4040

4141
+ (RCTBridge *)getRCTBridge;
42-
+ (void) checkExpiredSessions;
4342

4443
@end
4544

ios/RNFetchBlob/RNFetchBlob.m

+16-8
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ - (dispatch_queue_t) methodQueue {
3838

3939
+ (RCTBridge *)getRCTBridge
4040
{
41-
RCTRootView * rootView = [[UIApplication sharedApplication] keyWindow].rootViewController.view;
41+
RCTRootView * rootView = (RCTRootView*) [[UIApplication sharedApplication] keyWindow].rootViewController.view;
4242
return rootView.bridge;
4343
}
4444

@@ -96,8 +96,12 @@ - (NSDictionary *)constantsToExport
9696
// send HTTP request
9797
else
9898
{
99-
RNFetchBlobNetwork * utils = [[RNFetchBlobNetwork alloc] init];
100-
[utils sendRequest:options contentLength:bodyLength bridge:self.bridge taskId:taskId withRequest:req callback:callback];
99+
[[RNFetchBlobNetwork sharedInstance] sendRequest:options
100+
contentLength:bodyLength
101+
bridge:self.bridge
102+
taskId:taskId
103+
withRequest:req
104+
callback:callback];
101105
}
102106
}];
103107

@@ -128,8 +132,12 @@ - (NSDictionary *)constantsToExport
128132
// send HTTP request
129133
else
130134
{
131-
__block RNFetchBlobNetwork * utils = [[RNFetchBlobNetwork alloc] init];
132-
[utils sendRequest:options contentLength:bodyLength bridge:self.bridge taskId:taskId withRequest:req callback:callback];
135+
[[RNFetchBlobNetwork sharedInstance] sendRequest:options
136+
contentLength:bodyLength
137+
bridge:self.bridge
138+
taskId:taskId
139+
withRequest:req
140+
callback:callback];
133141
}
134142
}];
135143
}
@@ -488,7 +496,7 @@ - (NSDictionary *)constantsToExport
488496

489497
#pragma mark - net.cancelRequest
490498
RCT_EXPORT_METHOD(cancelRequest:(NSString *)taskId callback:(RCTResponseSenderBlock)callback) {
491-
[RNFetchBlobNetwork cancelRequest:taskId];
499+
[[RNFetchBlobNetwork sharedInstance] cancelRequest:taskId];
492500
callback(@[[NSNull null], taskId]);
493501

494502
}
@@ -498,14 +506,14 @@ - (NSDictionary *)constantsToExport
498506
{
499507

500508
RNFetchBlobProgress * cfg = [[RNFetchBlobProgress alloc] initWithType:Download interval:interval count:count];
501-
[RNFetchBlobNetwork enableProgressReport:taskId config:cfg];
509+
[[RNFetchBlobNetwork sharedInstance] enableProgressReport:taskId config:cfg];
502510
}
503511

504512
#pragma mark - net.enableUploadProgressReport
505513
RCT_EXPORT_METHOD(enableUploadProgressReport:(NSString *)taskId interval:(nonnull NSNumber*)interval count:(nonnull NSNumber*)count)
506514
{
507515
RNFetchBlobProgress * cfg = [[RNFetchBlobProgress alloc] initWithType:Upload interval:interval count:count];
508-
[RNFetchBlobNetwork enableUploadProgress:taskId config:cfg];
516+
[[RNFetchBlobNetwork sharedInstance] enableUploadProgress:taskId config:cfg];
509517
}
510518

511519
#pragma mark - fs.slice

ios/RNFetchBlobConst.m

+28-28
Original file line numberDiff line numberDiff line change
@@ -7,38 +7,38 @@
77
//
88
#import "RNFetchBlobConst.h"
99

10-
extern NSString *const FILE_PREFIX = @"RNFetchBlob-file://";
11-
extern NSString *const ASSET_PREFIX = @"bundle-assets://";
12-
extern NSString *const AL_PREFIX = @"assets-library://";
10+
NSString *const FILE_PREFIX = @"RNFetchBlob-file://";
11+
NSString *const ASSET_PREFIX = @"bundle-assets://";
12+
NSString *const AL_PREFIX = @"assets-library://";
1313

1414
// fetch configs
15-
extern NSString *const CONFIG_USE_TEMP = @"fileCache";
16-
extern NSString *const CONFIG_FILE_PATH = @"path";
17-
extern NSString *const CONFIG_FILE_EXT = @"appendExt";
18-
extern NSString *const CONFIG_TRUSTY = @"trusty";
19-
extern NSString *const CONFIG_INDICATOR = @"indicator";
20-
extern NSString *const CONFIG_KEY = @"key";
21-
extern NSString *const CONFIG_EXTRA_BLOB_CTYPE = @"binaryContentTypes";
15+
NSString *const CONFIG_USE_TEMP = @"fileCache";
16+
NSString *const CONFIG_FILE_PATH = @"path";
17+
NSString *const CONFIG_FILE_EXT = @"appendExt";
18+
NSString *const CONFIG_TRUSTY = @"trusty";
19+
NSString *const CONFIG_INDICATOR = @"indicator";
20+
NSString *const CONFIG_KEY = @"key";
21+
NSString *const CONFIG_EXTRA_BLOB_CTYPE = @"binaryContentTypes";
2222

23-
extern NSString *const EVENT_STATE_CHANGE = @"RNFetchBlobState";
24-
extern NSString *const EVENT_SERVER_PUSH = @"RNFetchBlobServerPush";
25-
extern NSString *const EVENT_PROGRESS = @"RNFetchBlobProgress";
26-
extern NSString *const EVENT_PROGRESS_UPLOAD = @"RNFetchBlobProgress-upload";
27-
extern NSString *const EVENT_EXPIRE = @"RNFetchBlobExpire";
23+
NSString *const EVENT_STATE_CHANGE = @"RNFetchBlobState";
24+
NSString *const EVENT_SERVER_PUSH = @"RNFetchBlobServerPush";
25+
NSString *const EVENT_PROGRESS = @"RNFetchBlobProgress";
26+
NSString *const EVENT_PROGRESS_UPLOAD = @"RNFetchBlobProgress-upload";
27+
NSString *const EVENT_EXPIRE = @"RNFetchBlobExpire";
2828

29-
extern NSString *const MSG_EVENT = @"RNFetchBlobMessage";
30-
extern NSString *const MSG_EVENT_LOG = @"log";
31-
extern NSString *const MSG_EVENT_WARN = @"warn";
32-
extern NSString *const MSG_EVENT_ERROR = @"error";
33-
extern NSString *const FS_EVENT_DATA = @"data";
34-
extern NSString *const FS_EVENT_END = @"end";
35-
extern NSString *const FS_EVENT_WARN = @"warn";
36-
extern NSString *const FS_EVENT_ERROR = @"error";
29+
NSString *const MSG_EVENT = @"RNFetchBlobMessage";
30+
NSString *const MSG_EVENT_LOG = @"log";
31+
NSString *const MSG_EVENT_WARN = @"warn";
32+
NSString *const MSG_EVENT_ERROR = @"error";
33+
NSString *const FS_EVENT_DATA = @"data";
34+
NSString *const FS_EVENT_END = @"end";
35+
NSString *const FS_EVENT_WARN = @"warn";
36+
NSString *const FS_EVENT_ERROR = @"error";
3737

38-
extern NSString *const KEY_REPORT_PROGRESS = @"reportProgress";
39-
extern NSString *const KEY_REPORT_UPLOAD_PROGRESS = @"reportUploadProgress";
38+
NSString *const KEY_REPORT_PROGRESS = @"reportProgress";
39+
NSString *const KEY_REPORT_UPLOAD_PROGRESS = @"reportUploadProgress";
4040

4141
// response type
42-
extern NSString *const RESP_TYPE_BASE64 = @"base64";
43-
extern NSString *const RESP_TYPE_UTF8 = @"utf8";
44-
extern NSString *const RESP_TYPE_PATH = @"path";
42+
NSString *const RESP_TYPE_BASE64 = @"base64";
43+
NSString *const RESP_TYPE_UTF8 = @"utf8";
44+
NSString *const RESP_TYPE_PATH = @"path";

ios/RNFetchBlobFS.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@
3434
NSString * streamId;
3535
}
3636

37-
@property (nonatomic) NSOutputStream * outStream;
38-
@property (nonatomic) NSInputStream * inStream;
37+
@property (nonatomic) NSOutputStream * _Nullable outStream;
38+
@property (nonatomic) NSInputStream * _Nullable inStream;
3939
@property (strong, nonatomic) RCTResponseSenderBlock callback;
4040
@property (nonatomic) RCTBridge * bridge;
4141
@property (nonatomic) NSString * encoding;

ios/RNFetchBlobNetwork.h

+16-28
Original file line numberDiff line numberDiff line change
@@ -6,52 +6,40 @@
66
// Copyright © 2016 wkh237. All rights reserved.
77
//
88

9+
#ifndef RNFetchBlobNetwork_h
10+
#define RNFetchBlobNetwork_h
11+
912
#import <Foundation/Foundation.h>
1013
#import "RNFetchBlobProgress.h"
1114
#import "RNFetchBlobFS.h"
15+
#import "RNFetchBlobRequest.h"
1216

1317
#if __has_include(<React/RCTAssert.h>)
1418
#import <React/RCTBridgeModule.h>
1519
#else
1620
#import "RCTBridgeModule.h"
1721
#endif
1822

19-
#ifndef RNFetchBlobNetwork_h
20-
#define RNFetchBlobNetwork_h
21-
22-
23-
24-
typedef void(^CompletionHander)(NSURL * _Nullable location, NSURLResponse * _Nullable response, NSError * _Nullable error);
25-
typedef void(^DataTaskCompletionHander) (NSData * _Nullable resp, NSURLResponse * _Nullable response, NSError * _Nullable error);
2623

2724
@interface RNFetchBlobNetwork : NSObject <NSURLSessionDelegate, NSURLSessionTaskDelegate, NSURLSessionDataDelegate>
2825

29-
@property (nullable, nonatomic) NSString * taskId;
30-
@property (nonatomic) int expectedBytes;
31-
@property (nonatomic) int receivedBytes;
32-
@property (nonatomic) BOOL isServerPush;
33-
@property (nullable, nonatomic) NSMutableData * respData;
34-
@property (strong, nonatomic) RCTResponseSenderBlock callback;
35-
@property (nullable, nonatomic) RCTBridge * bridge;
36-
@property (nullable, nonatomic) NSDictionary * options;
37-
@property (nullable, nonatomic) RNFetchBlobFS * fileStream;
38-
@property (strong, nonatomic) CompletionHander fileTaskCompletionHandler;
39-
@property (strong, nonatomic) DataTaskCompletionHander dataTaskCompletionHandler;
40-
@property (nullable, nonatomic) NSError * error;
41-
26+
@property(nonnull, nonatomic) NSOperationQueue *taskQueue;
27+
@property(nonnull, nonatomic) NSMapTable<NSString*, RNFetchBlobRequest*> * requestsTable;
4228

29+
+ (RNFetchBlobNetwork* _Nullable)sharedInstance;
4330
+ (NSMutableDictionary * _Nullable ) normalizeHeaders:(NSDictionary * _Nullable)headers;
44-
+ (void) cancelRequest:(NSString *)taskId;
45-
+ (void) enableProgressReport:(NSString *) taskId;
46-
+ (void) enableUploadProgress:(NSString *) taskId;
4731
+ (void) emitExpiredTasks;
4832

4933
- (nullable id) init;
50-
- (void) sendRequest;
51-
- (void) sendRequest:(NSDictionary * _Nullable )options contentLength:(long)contentLength bridge:(RCTBridge * _Nullable)bridgeRef taskId:(NSString * _Nullable)taskId withRequest:(NSURLRequest * _Nullable)req callback:(_Nullable RCTResponseSenderBlock) callback;
52-
+ (void) enableProgressReport:(NSString *) taskId config:(RNFetchBlobProgress *)config;
53-
+ (void) enableUploadProgress:(NSString *) taskId config:(RNFetchBlobProgress *)config;
54-
34+
- (void) sendRequest:(NSDictionary * _Nullable )options
35+
contentLength:(long)contentLength
36+
bridge:(RCTBridge * _Nullable)bridgeRef
37+
taskId:(NSString * _Nullable)taskId
38+
withRequest:(NSURLRequest * _Nullable)req
39+
callback:(_Nullable RCTResponseSenderBlock) callback;
40+
- (void) cancelRequest:(NSString * _Nonnull)taskId;
41+
- (void) enableProgressReport:(NSString * _Nonnull) taskId config:(RNFetchBlobProgress * _Nullable)config;
42+
- (void) enableUploadProgress:(NSString * _Nonnull) taskId config:(RNFetchBlobProgress * _Nullable)config;
5543

5644

5745
@end

0 commit comments

Comments
 (0)