Skip to content

Commit 8dd310d

Browse files
author
Artur Chrusciel
committed
Separate requests from network logic
1 parent f0301db commit 8dd310d

File tree

6 files changed

+616
-544
lines changed

6 files changed

+616
-544
lines changed

ios/RNFetchBlob.xcodeproj/project.pbxproj

Lines changed: 7 additions & 1 deletion
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.m

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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 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-
RNFetchBlobNetwork * utils = [[RNFetchBlobNetwork alloc] init];
132-
[utils sendRequest:options contentLength:bodyLength bridge:self.bridge taskId:taskId withRequest:req callback:callback];
135+
[RNFetchBlobNetwork sendRequest:options
136+
contentLength:bodyLength
137+
bridge:self.bridge
138+
taskId:taskId
139+
withRequest:req
140+
callback:callback];
133141
}
134142
}];
135143
}

ios/RNFetchBlobNetwork.h

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,26 +22,16 @@
2222

2323
@interface RNFetchBlobNetwork : NSObject <NSURLSessionDelegate, NSURLSessionTaskDelegate, NSURLSessionDataDelegate>
2424

25-
@property (nullable, nonatomic) NSString * taskId;
26-
@property (nonatomic) long long expectedBytes;
27-
@property (nonatomic) long long receivedBytes;
28-
@property (nonatomic) BOOL isServerPush;
29-
@property (nullable, nonatomic) NSMutableData * respData;
30-
@property (nullable, strong, nonatomic) RCTResponseSenderBlock callback;
31-
@property (nullable, nonatomic) RCTBridge * bridge;
32-
@property (nullable, nonatomic) NSDictionary * options;
33-
@property (nullable, nonatomic) RNFetchBlobFS * fileStream;
34-
@property (nullable, nonatomic) NSError * error;
35-
3625

26+
+ (_Nullable instancetype)sharedInstance;
3727
+ (NSMutableDictionary * _Nullable ) normalizeHeaders:(NSDictionary * _Nullable)headers;
3828
+ (void) cancelRequest:(NSString * _Nonnull)taskId;
3929
+ (void) emitExpiredTasks;
4030
+ (void) enableProgressReport:(NSString * _Nonnull) taskId config:(RNFetchBlobProgress * _Nullable)config;
4131
+ (void) enableUploadProgress:(NSString * _Nonnull) taskId config:(RNFetchBlobProgress * _Nullable)config;
4232

4333
- (nullable id) init;
44-
- (void) sendRequest:(NSDictionary * _Nullable )options contentLength:(long)contentLength bridge:(RCTBridge * _Nullable)bridgeRef taskId:(NSString * _Nullable)taskId withRequest:(NSURLRequest * _Nullable)req callback:(_Nullable RCTResponseSenderBlock) callback;
34+
+ (void) sendRequest:(NSDictionary * _Nullable )options contentLength:(long)contentLength bridge:(RCTBridge * _Nullable)bridgeRef taskId:(NSString * _Nullable)taskId withRequest:(NSURLRequest * _Nullable)req callback:(_Nullable RCTResponseSenderBlock) callback;
4535

4636
@end
4737

0 commit comments

Comments
 (0)