소스 검색

Add network status indicator support

Ben Hsieh 8 년 전
부모
커밋
0bcf47ea27
7개의 변경된 파일36개의 추가작업 그리고 18개의 파일을 삭제
  1. 2
    1
      README.md
  2. 1
    0
      src/ios/RNFetchBlobConst.h
  3. 1
    0
      src/ios/RNFetchBlobConst.m
  4. 12
    10
      src/ios/RNFetchBlobFS.m
  5. 16
    5
      src/ios/RNFetchBlobNetwork.m
  6. 1
    1
      src/package.json
  7. 3
    1
      src/types.js

+ 2
- 1
README.md 파일 보기

@@ -1,4 +1,4 @@
1
-# react-native-fetch-blob [![npm version](https://img.shields.io/badge/npm package-0.5.5-brightgreen.svg)](https://badge.fury.io/js/react-native-fetch-blob) ![](https://img.shields.io/badge/PR-Welcome-brightgreen.svg) ![](https://img.shields.io/badge/in progress-0.6.0-yellow.svg)
1
+# react-native-fetch-blob [![npm version](https://img.shields.io/badge/npm package-0.5.6-brightgreen.svg)](https://badge.fury.io/js/react-native-fetch-blob) ![](https://img.shields.io/badge/PR-Welcome-brightgreen.svg) ![](https://img.shields.io/badge/in progress-0.6.0-yellow.svg)
2 2
 
3 3
 A module provides upload, download, and files access API. Supports file stream read/write for process large files.
4 4
 
@@ -847,6 +847,7 @@ A `session` is an object that helps you manage files. It simply maintains a list
847 847
 
848 848
 | Version | |
849 849
 |---|---|
850
+| 0.5.6 | Add support for IOS network status indicator. Fix file stream ASCII reader bug. |
850 851
 | 0.5.5 | Remove work in progress code added in 0.5.2 which may cause memory leaks. |
851 852
 | 0.5.4 | Fix #30 #31 build build error, and improve memory efficiency. |
852 853
 | 0.5.3 | Add API for access untrusted SSL server |

+ 1
- 0
src/ios/RNFetchBlobConst.h 파일 보기

@@ -23,6 +23,7 @@ extern NSString *const CONFIG_USE_TEMP;
23 23
 extern NSString *const CONFIG_FILE_PATH;
24 24
 extern NSString *const CONFIG_FILE_EXT;
25 25
 extern NSString *const CONFIG_TRUSTY;
26
+extern NSString *const CONFIG_INDICATOR;
26 27
 
27 28
 // fs events
28 29
 extern NSString *const FS_EVENT_DATA;

+ 1
- 0
src/ios/RNFetchBlobConst.m 파일 보기

@@ -14,6 +14,7 @@ extern NSString *const CONFIG_USE_TEMP = @"fileCache";
14 14
 extern NSString *const CONFIG_FILE_PATH = @"path";
15 15
 extern NSString *const CONFIG_FILE_EXT = @"appendExt";
16 16
 extern NSString *const CONFIG_TRUSTY = @"trusty";
17
+extern NSString *const CONFIG_INDICATOR = @"indicator";
17 18
 
18 19
 
19 20
 extern NSString *const MSG_EVENT = @"RNFetchBlobMessage";

+ 12
- 10
src/ios/RNFetchBlobFS.m 파일 보기

@@ -264,7 +264,8 @@ void runOnMainQueueWithoutDeadlocking(void (^block)(void))
264 264
                 chunkSize = 4095;
265 265
             if(self.bufferSize > 0)
266 266
                 chunkSize = self.bufferSize;
267
-            uint8_t * buf = (uint8_t *)malloc(chunkSize);
267
+//            uint8_t * buf = (uint8_t *)malloc(chunkSize);
268
+            uint8_t buf[chunkSize];
268 269
             unsigned int len = 0;
269 270
             len = [(NSInputStream *)stream read:buf maxLength:chunkSize];
270 271
             // still have data in stream
@@ -281,6 +282,7 @@ void runOnMainQueueWithoutDeadlocking(void (^block)(void))
281 282
                     NSString * asciiStr = @"[";
282 283
                     if (chunkData.length > 0)
283 284
                     {
285
+//                        unsigned char *bytePtr = (unsigned char *)[chunkData bytes];
284 286
                         unsigned char *bytePtr = (unsigned char *)[chunkData bytes];
285 287
                         NSInteger byteLen = chunkData.length/sizeof(uint8_t);
286 288
                         for (int i = 0; i < byteLen; i++)
@@ -291,7 +293,7 @@ void runOnMainQueueWithoutDeadlocking(void (^block)(void))
291 293
                             else
292 294
                                 asciiStr = [asciiStr stringByAppendingFormat:@"%d", val];
293 295
                         }
294
-                        free(bytePtr);
296
+//                        free(bytePtr);
295 297
                     }
296 298
                     asciiStr = [asciiStr stringByAppendingString:@"]"];
297 299
                     [self.bridge.eventDispatcher
@@ -301,10 +303,10 @@ void runOnMainQueueWithoutDeadlocking(void (^block)(void))
301 303
                              @"detail": asciiStr
302 304
                             }
303 305
                      ];
304
-                    free(buf);
305
-                    asciiStr = nil;
306
-                    buf = nil;
307
-                    chunkData = nil;
306
+//                    free(buf);
307
+//                    asciiStr = nil;
308
+//                    buf = nil;
309
+//                    chunkData = nil;
308 310
                     return;
309 311
                 }
310 312
                 // convert byte array to base64 data chunks
@@ -330,8 +332,8 @@ void runOnMainQueueWithoutDeadlocking(void (^block)(void))
330 332
                         @"detail": encodedChunk
331 333
                         }
332 334
                  ];
333
-                chunkData = nil;
334
-                free(buf);
335
+//                chunkData = nil;
336
+//                free(buf);
335 337
             }
336 338
             // end of stream
337 339
             else {
@@ -342,8 +344,8 @@ void runOnMainQueueWithoutDeadlocking(void (^block)(void))
342 344
                         @"detail": @""
343 345
                         }
344 346
                  ];
345
-                chunkData = nil;
346
-                free(buf);
347
+//                chunkData = nil;
348
+//                free(buf);
347 349
             }
348 350
             break;
349 351
         }

+ 16
- 5
src/ios/RNFetchBlobNetwork.m 파일 보기

@@ -77,7 +77,7 @@ NSOperationQueue *taskQueue;
77 77
     if([options valueForKey:CONFIG_TRUSTY] != nil)
78 78
     {
79 79
         NSURLSessionConfiguration *defaultConfigObject = [NSURLSessionConfiguration defaultSessionConfiguration];
80
-        session = [NSURLSession sessionWithConfiguration:defaultConfigObject delegate:self delegateQueue:taskQueue];
80
+        session = [NSURLSession sessionWithConfiguration:defaultConfigObject delegate:self delegateQueue:[NSOperationQueue mainQueue]];
81 81
     }
82 82
     // the session validates SSL certification, self-signed certification will be aborted
83 83
     else
@@ -105,6 +105,7 @@ NSOperationQueue *taskQueue;
105 105
             callback(@[[NSNull null], path]);
106 106
             // prevent memory leaks
107 107
             self.respData = nil;
108
+            [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
108 109
         }];
109 110
         [task resume];
110 111
     }
@@ -127,6 +128,7 @@ NSOperationQueue *taskQueue;
127 128
                 return;
128 129
             }
129 130
             callback(@[[NSNull null], tmpPath]);
131
+            [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
130 132
             // prevent memory leaks
131 133
             self.respData = nil;
132 134
         }];
@@ -143,9 +145,15 @@ NSOperationQueue *taskQueue;
143 145
             else {
144 146
                 callback(@[[NSNull null], [resp base64EncodedStringWithOptions:0]]);
145 147
             }
148
+            self.respData = nil;
149
+            [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
146 150
         }];
147 151
         [task resume];
148 152
     }
153
+    
154
+    // network status indicator
155
+    if([[options objectForKey:CONFIG_INDICATOR] boolValue] == YES)
156
+        [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
149 157
 }
150 158
 
151 159
 ////////////////////////////////////////
@@ -188,6 +196,7 @@ NSOperationQueue *taskQueue;
188 196
 - (void) URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didCompleteWithError:(NSError *)error {
189 197
     NSLog([error localizedDescription]);
190 198
     self.error = error;
199
+    [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
191 200
 }
192 201
 
193 202
 // upload progress handler
@@ -205,9 +214,9 @@ NSOperationQueue *taskQueue;
205 214
      ];
206 215
 }
207 216
 
208
-- (void) application:(UIApplication *)application handleEventsForBackgroundURLSession:(NSString *)identifier completionHandler:(void (^)())completionHandler {
209
-    
210
-}
217
+//- (void) application:(UIApplication *)application handleEventsForBackgroundURLSession:(NSString *)identifier completionHandler:(void (^)())completionHandler {
218
+//    
219
+//}
211 220
 
212 221
 //- (void) URLSessionDidFinishEventsForBackgroundURLSession:(NSURLSession *)session
213 222
 //{
@@ -225,8 +234,10 @@ NSOperationQueue *taskQueue;
225 234
 {
226 235
     if([options valueForKey:CONFIG_TRUSTY] != nil)
227 236
         completionHandler(NSURLSessionAuthChallengeUseCredential, [NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust]);
228
-    else
237
+    else {
229 238
         RCTLogWarn(@"counld not create connection with an unstrusted SSL certification, if you're going to create connection anyway, add `trusty:true` to RNFetchBlob.config");
239
+        [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
240
+    }
230 241
 }
231 242
 
232 243
 @end

+ 1
- 1
src/package.json 파일 보기

@@ -1,6 +1,6 @@
1 1
 {
2 2
   "name": "react-native-fetch-blob",
3
-  "version": "0.5.5",
3
+  "version": "0.5.6",
4 4
   "description": "A module provides upload, download, and files access API. Supports file stream read/write for process large files.",
5 5
   "main": "index.js",
6 6
   "scripts": {

+ 3
- 1
src/types.js 파일 보기

@@ -3,7 +3,9 @@ type RNFetchBlobConfig = {
3 3
   fileCache : bool,
4 4
   path : string,
5 5
   appendExt : string,
6
-  session : string
6
+  session : string,
7
+  addAndroidDownloads : any,
8
+  indicator : bool
7 9
 };
8 10
 
9 11
 type RNFetchBlobNative = {