Selaa lähdekoodia

Enhance ios native error handling

Ben Hsieh 8 vuotta sitten
vanhempi
commit
1e2d86b7bd
2 muutettua tiedostoa jossa 16 lisäystä ja 45 poistoa
  1. 0
    36
      src/ios/RNFetchBlob.xcodeproj/project.pbxproj
  2. 16
    9
      src/ios/RNFetchBlob/RNFetchBlob.m

+ 0
- 36
src/ios/RNFetchBlob.xcodeproj/project.pbxproj Näytä tiedosto

@@ -11,16 +11,6 @@
11 11
 		A166D1AA1CE0647A00273590 /* RNFetchBlob.h in Sources */ = {isa = PBXBuildFile; fileRef = A15C30111CD25C330074CB35 /* RNFetchBlob.h */; };
12 12
 /* End PBXBuildFile section */
13 13
 
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
-
24 14
 /* Begin PBXCopyFilesBuildPhase section */
25 15
 		A15C300C1CD25C330074CB35 /* CopyFiles */ = {
26 16
 			isa = PBXCopyFilesBuildPhase;
@@ -37,7 +27,6 @@
37 27
 		A15C300E1CD25C330074CB35 /* libRNFetchBlob.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libRNFetchBlob.a; sourceTree = BUILT_PRODUCTS_DIR; };
38 28
 		A15C30111CD25C330074CB35 /* RNFetchBlob.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = RNFetchBlob.h; path = RNFetchBlob/RNFetchBlob.h; sourceTree = "<group>"; };
39 29
 		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>"; };
41 30
 /* End PBXFileReference section */
42 31
 
43 32
 /* Begin PBXFrameworksBuildPhase section */
@@ -54,7 +43,6 @@
54 43
 		8BD9ABDFAF76406291A798F2 /* Libraries */ = {
55 44
 			isa = PBXGroup;
56 45
 			children = (
57
-				ADC1D945EE804D3DA47CF622 /* RNFetchBlob.xcodeproj */,
58 46
 			);
59 47
 			name = Libraries;
60 48
 			sourceTree = "<group>";
@@ -77,14 +65,6 @@
77 65
 			name = Products;
78 66
 			sourceTree = "<group>";
79 67
 		};
80
-		A1BAA8981CF415DF003A9374 /* Products */ = {
81
-			isa = PBXGroup;
82
-			children = (
83
-				A1BAA89F1CF415DF003A9374 /* libRNFetchBlob.a */,
84
-			);
85
-			name = Products;
86
-			sourceTree = "<group>";
87
-		};
88 68
 /* End PBXGroup section */
89 69
 
90 70
 /* Begin PBXNativeTarget section */
@@ -129,12 +109,6 @@
129 109
 			mainGroup = A15C30051CD25C330074CB35;
130 110
 			productRefGroup = A15C300F1CD25C330074CB35 /* Products */;
131 111
 			projectDirPath = "";
132
-			projectReferences = (
133
-				{
134
-					ProductGroup = A1BAA8981CF415DF003A9374 /* Products */;
135
-					ProjectRef = ADC1D945EE804D3DA47CF622 /* RNFetchBlob.xcodeproj */;
136
-				},
137
-			);
138 112
 			projectRoot = "";
139 113
 			targets = (
140 114
 				A15C300D1CD25C330074CB35 /* RNFetchBlob */,
@@ -142,16 +116,6 @@
142 116
 		};
143 117
 /* End PBXProject section */
144 118
 
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
-
155 119
 /* Begin PBXSourcesBuildPhase section */
156 120
 		A15C300A1CD25C330074CB35 /* Sources */ = {
157 121
 			isa = PBXSourcesBuildPhase;

+ 16
- 9
src/ios/RNFetchBlob/RNFetchBlob.m Näytä tiedosto

@@ -122,7 +122,13 @@
122 122
 
123 123
 // request complete
124 124
 - (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
+    
126 132
     callback(@[[NSNull null], [data base64EncodedStringWithOptions:0]]);
127 133
 }
128 134
 
@@ -168,7 +174,7 @@ RCT_EXPORT_METHOD(fetchBlobForm:(NSString *)taskId method:(NSString *)method url
168 174
             NSString * name = [field valueForKey:@"name"];
169 175
             NSString * content = [field valueForKey:@"data"];
170 176
             // field is a text field
171
-            if([field valueForKey:@"filename"] == nil) {
177
+            if([field valueForKey:@"filename"] == nil || content == [NSNull null]) {
172 178
                 [postData appendData:[[NSString stringWithFormat:@"--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
173 179
                 [postData appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"%@\"\r\n", name] dataUsingEncoding:NSUTF8StringEncoding]];
174 180
                 [postData appendData:[[NSString stringWithFormat:@"Content-Type: text/plain\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
@@ -225,13 +231,14 @@ RCT_EXPORT_METHOD(fetchBlob:(NSString *)taskId method:(NSString *)method url:(NS
225 231
     // if method is POST or PUT, convert data string format
226 232
     if([[method lowercaseString] isEqualToString:@"post"] || [[method lowercaseString] isEqualToString:@"put"]) {
227 233
         
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
+        }
235 242
     }
236 243
     
237 244
     [request setHTTPMethod: method];