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

Commit 1e2d86b

Browse files
committed
Enhance ios native error handling
1 parent d0455c9 commit 1e2d86b

File tree

2 files changed

+16
-45
lines changed

2 files changed

+16
-45
lines changed

src/ios/RNFetchBlob.xcodeproj/project.pbxproj

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,6 @@
1111
A166D1AA1CE0647A00273590 /* RNFetchBlob.h in Sources */ = {isa = PBXBuildFile; fileRef = A15C30111CD25C330074CB35 /* RNFetchBlob.h */; };
1212
/* End PBXBuildFile section */
1313

14-
/* Begin PBXContainerItemProxy section */
15-
A1BAA89E1CF415DF003A9374 /* PBXContainerItemProxy */ = {
16-
isa = PBXContainerItemProxy;
17-
containerPortal = ADC1D945EE804D3DA47CF622 /* RNFetchBlob.xcodeproj */;
18-
proxyType = 2;
19-
remoteGlobalIDString = A15C300E1CD25C330074CB35;
20-
remoteInfo = RNFetchBlob;
21-
};
22-
/* End PBXContainerItemProxy section */
23-
2414
/* Begin PBXCopyFilesBuildPhase section */
2515
A15C300C1CD25C330074CB35 /* CopyFiles */ = {
2616
isa = PBXCopyFilesBuildPhase;
@@ -37,7 +27,6 @@
3727
A15C300E1CD25C330074CB35 /* libRNFetchBlob.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libRNFetchBlob.a; sourceTree = BUILT_PRODUCTS_DIR; };
3828
A15C30111CD25C330074CB35 /* RNFetchBlob.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = RNFetchBlob.h; path = RNFetchBlob/RNFetchBlob.h; sourceTree = "<group>"; };
3929
A15C30131CD25C330074CB35 /* RNFetchBlob.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = RNFetchBlob.m; path = RNFetchBlob/RNFetchBlob.m; sourceTree = "<group>"; };
40-
ADC1D945EE804D3DA47CF622 /* RNFetchBlob.xcodeproj */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = 9; includeInIndex = 0; lastKnownFileType = "wrapper.pb-project"; name = RNFetchBlob.xcodeproj; path = "../../node_modules/react-native-fetch-blob/ios/RNFetchBlob.xcodeproj"; sourceTree = "<group>"; };
4130
/* End PBXFileReference section */
4231

4332
/* Begin PBXFrameworksBuildPhase section */
@@ -54,7 +43,6 @@
5443
8BD9ABDFAF76406291A798F2 /* Libraries */ = {
5544
isa = PBXGroup;
5645
children = (
57-
ADC1D945EE804D3DA47CF622 /* RNFetchBlob.xcodeproj */,
5846
);
5947
name = Libraries;
6048
sourceTree = "<group>";
@@ -77,14 +65,6 @@
7765
name = Products;
7866
sourceTree = "<group>";
7967
};
80-
A1BAA8981CF415DF003A9374 /* Products */ = {
81-
isa = PBXGroup;
82-
children = (
83-
A1BAA89F1CF415DF003A9374 /* libRNFetchBlob.a */,
84-
);
85-
name = Products;
86-
sourceTree = "<group>";
87-
};
8868
/* End PBXGroup section */
8969

9070
/* Begin PBXNativeTarget section */
@@ -129,29 +109,13 @@
129109
mainGroup = A15C30051CD25C330074CB35;
130110
productRefGroup = A15C300F1CD25C330074CB35 /* Products */;
131111
projectDirPath = "";
132-
projectReferences = (
133-
{
134-
ProductGroup = A1BAA8981CF415DF003A9374 /* Products */;
135-
ProjectRef = ADC1D945EE804D3DA47CF622 /* RNFetchBlob.xcodeproj */;
136-
},
137-
);
138112
projectRoot = "";
139113
targets = (
140114
A15C300D1CD25C330074CB35 /* RNFetchBlob */,
141115
);
142116
};
143117
/* End PBXProject section */
144118

145-
/* Begin PBXReferenceProxy section */
146-
A1BAA89F1CF415DF003A9374 /* libRNFetchBlob.a */ = {
147-
isa = PBXReferenceProxy;
148-
fileType = archive.ar;
149-
path = libRNFetchBlob.a;
150-
remoteRef = A1BAA89E1CF415DF003A9374 /* PBXContainerItemProxy */;
151-
sourceTree = BUILT_PRODUCTS_DIR;
152-
};
153-
/* End PBXReferenceProxy section */
154-
155119
/* Begin PBXSourcesBuildPhase section */
156120
A15C300A1CD25C330074CB35 /* Sources */ = {
157121
isa = PBXSourcesBuildPhase;

src/ios/RNFetchBlob/RNFetchBlob.m

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,13 @@ - (NSURLRequest *)connection:(NSURLConnection *)connection willSendRequest:(NSUR
122122

123123
// request complete
124124
- (void) connectionDidFinishLoading:(NSURLConnection *)connection {
125-
NSData * data = [NSData dataWithData:respData];
125+
126+
NSData * data;
127+
if(respData != nil)
128+
data = [NSData dataWithData:respData];
129+
else
130+
data = [[NSData alloc] init];
131+
126132
callback(@[[NSNull null], [data base64EncodedStringWithOptions:0]]);
127133
}
128134

@@ -168,7 +174,7 @@ @implementation RNFetchBlob
168174
NSString * name = [field valueForKey:@"name"];
169175
NSString * content = [field valueForKey:@"data"];
170176
// field is a text field
171-
if([field valueForKey:@"filename"] == nil) {
177+
if([field valueForKey:@"filename"] == nil || content == [NSNull null]) {
172178
[postData appendData:[[NSString stringWithFormat:@"--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
173179
[postData appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"%@\"\r\n", name] dataUsingEncoding:NSUTF8StringEncoding]];
174180
[postData appendData:[[NSString stringWithFormat:@"Content-Type: text/plain\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
@@ -225,13 +231,14 @@ @implementation RNFetchBlob
225231
// if method is POST or PUT, convert data string format
226232
if([[method lowercaseString] isEqualToString:@"post"] || [[method lowercaseString] isEqualToString:@"put"]) {
227233

228-
// generate octet-stream body
229-
NSData* blobData = [[NSData alloc] initWithBase64EncodedString:body options:0];
230-
NSMutableData* postBody = [[NSMutableData alloc] init];
231-
[postBody appendData:[NSData dataWithData:blobData]];
232-
[request setHTTPBody:postBody];
233-
[mheaders setValue:@"application/octet-stream" forKey:@"content-type"];
234-
234+
if(body != nil) {
235+
// generate octet-stream body
236+
NSData* blobData = [[NSData alloc] initWithBase64EncodedString:body options:0];
237+
NSMutableData* postBody = [[NSMutableData alloc] init];
238+
[postBody appendData:[NSData dataWithData:blobData]];
239+
[request setHTTPBody:postBody];
240+
[mheaders setValue:@"application/octet-stream" forKey:@"content-type"];
241+
}
235242
}
236243

237244
[request setHTTPMethod: method];

0 commit comments

Comments
 (0)