Browse Source

Apply fix for #263

Ben Hsieh 7 years ago
parent
commit
e7a39d9348
3 changed files with 34 additions and 29 deletions
  1. 3
    5
      src/index.js
  2. 18
    0
      src/ios/RNFetchBlobNetwork.h
  3. 13
    24
      src/ios/RNFetchBlobNetwork.m

+ 3
- 5
src/index.js View File

@@ -247,14 +247,12 @@ function fetch(...args:any):Promise {
247 247
     })
248 248
 
249 249
     stateEvent = emitter.addListener('RNFetchBlobState', (e) => {
250
-      respInfo = e
251
-      if(e.taskId === taskId && promise.onStateChange) {
252
-        promise.onStateChange(e)
253
-      }
250
+      if(e.taskId === taskId)
251
+        respInfo = e
252
+      promise.onStateChange && promise.onStateChange(e)
254 253
     })
255 254
 
256 255
     subscription = emitter.addListener('RNFetchBlobExpire', (e) => {
257
-      console.log(e , 'EXPIRED!!')
258 256
       if(e.taskId === taskId && promise.onExpire) {
259 257
         promise.onExpire(e)
260 258
       }

+ 18
- 0
src/ios/RNFetchBlobNetwork.h View File

@@ -23,6 +23,11 @@
23 23
 
24 24
 typedef void(^CompletionHander)(NSURL * _Nullable location, NSURLResponse * _Nullable response, NSError * _Nullable error);
25 25
 typedef void(^DataTaskCompletionHander) (NSData * _Nullable resp, NSURLResponse * _Nullable response, NSError * _Nullable error);
26
+typedef NS_ENUM(NSUInteger, ResponseFormat) {
27
+    UTF8,
28
+    BASE64,
29
+    AUTO
30
+};
26 31
 
27 32
 @interface RNFetchBlobNetwork : NSObject  <NSURLSessionDelegate, NSURLSessionTaskDelegate, NSURLSessionDataDelegate>
28 33
 
@@ -38,6 +43,19 @@ typedef void(^DataTaskCompletionHander) (NSData * _Nullable resp, NSURLResponse
38 43
 @property (strong, nonatomic) CompletionHander fileTaskCompletionHandler;
39 44
 @property (strong, nonatomic) DataTaskCompletionHander dataTaskCompletionHandler;
40 45
 @property (nullable, nonatomic) NSError * error;
46
+@property (nullable, nonatomic) NSMutableArray * redirects;
47
+
48
+@property (nonatomic) BOOL respFile;
49
+@property (nonatomic) BOOL isNewPart;
50
+@property (nonatomic) BOOL isIncrement;
51
+@property (nullable, nonatomic) NSMutableData * partBuffer;
52
+@property (nullable, nonatomic) NSString * destPath;
53
+@property (nullable, nonatomic) NSOutputStream * writeStream;
54
+@property (nonatomic) long bodyLength;
55
+@property (nullable, nonatomic) NSMutableDictionary * respInfo;
56
+@property (nonatomic) NSInteger respStatus;
57
+@property (nonatomic) ResponseFormat responseFormat;
58
+@property ( nonatomic) BOOL followRedirect;
41 59
 
42 60
 
43 61
 + (NSMutableDictionary  * _Nullable ) normalizeHeaders:(NSDictionary * _Nullable)headers;

+ 13
- 24
src/ios/RNFetchBlobNetwork.m View File

@@ -61,30 +61,6 @@ static void initialize_tables() {
61 61
 }
62 62
 
63 63
 
64
-typedef NS_ENUM(NSUInteger, ResponseFormat) {
65
-    UTF8,
66
-    BASE64,
67
-    AUTO
68
-};
69
-
70
-
71
-@interface RNFetchBlobNetwork ()
72
-{
73
-    BOOL * respFile;
74
-    BOOL isNewPart;
75
-    BOOL * isIncrement;
76
-    NSMutableData * partBuffer;
77
-    NSString * destPath;
78
-    NSOutputStream * writeStream;
79
-    long bodyLength;
80
-    NSMutableDictionary * respInfo;
81
-    NSInteger respStatus;
82
-    NSMutableArray * redirects;
83
-    ResponseFormat responseFormat;
84
-    BOOL * followRedirect;
85
-}
86
-
87
-@end
88 64
 
89 65
 @implementation RNFetchBlobNetwork
90 66
 
@@ -96,10 +72,23 @@ NSOperationQueue *taskQueue;
96 72
 @synthesize callback;
97 73
 @synthesize bridge;
98 74
 @synthesize options;
75
+@synthesize redirects;
99 76
 @synthesize fileTaskCompletionHandler;
100 77
 @synthesize dataTaskCompletionHandler;
101 78
 @synthesize error;
102 79
 
80
+@synthesize respFile;
81
+@synthesize isNewPart;
82
+@synthesize isIncrement;
83
+@synthesize partBuffer;
84
+@synthesize destPath;
85
+@synthesize writeStream;
86
+@synthesize bodyLength;
87
+@synthesize respInfo;
88
+@synthesize respStatus;
89
+@synthesize responseFormat;
90
+@synthesize followRedirect;
91
+
103 92
 
104 93
 // constructor
105 94
 - (id)init {