Browse Source

fix progress and uploadprogress not callback in iOS

wenshe 5 years ago
parent
commit
5551d01bf8
2 changed files with 29 additions and 2 deletions
  1. 2
    0
      ios/RNFetchBlobNetwork.h
  2. 27
    2
      ios/RNFetchBlobNetwork.m

+ 2
- 0
ios/RNFetchBlobNetwork.h View File

25
 
25
 
26
 @property(nonnull, nonatomic) NSOperationQueue *taskQueue;
26
 @property(nonnull, nonatomic) NSOperationQueue *taskQueue;
27
 @property(nonnull, nonatomic) NSMapTable<NSString*, RNFetchBlobRequest*> * requestsTable;
27
 @property(nonnull, nonatomic) NSMapTable<NSString*, RNFetchBlobRequest*> * requestsTable;
28
+@property(nonnull, nonatomic) NSMutableDictionary<NSString*, RNFetchBlobProgress*> *rebindProgressDict;
29
+@property(nonnull, nonatomic) NSMutableDictionary<NSString*, RNFetchBlobProgress*> *rebindUploadProgressDict;
28
 
30
 
29
 + (RNFetchBlobNetwork* _Nullable)sharedInstance;
31
 + (RNFetchBlobNetwork* _Nullable)sharedInstance;
30
 + (NSMutableDictionary  * _Nullable ) normalizeHeaders:(NSDictionary * _Nullable)headers;
32
 + (NSMutableDictionary  * _Nullable ) normalizeHeaders:(NSDictionary * _Nullable)headers;

+ 27
- 2
ios/RNFetchBlobNetwork.m View File

53
         self.taskQueue = [[NSOperationQueue alloc] init];
53
         self.taskQueue = [[NSOperationQueue alloc] init];
54
         self.taskQueue.qualityOfService = NSQualityOfServiceUtility;
54
         self.taskQueue.qualityOfService = NSQualityOfServiceUtility;
55
         self.taskQueue.maxConcurrentOperationCount = 10;
55
         self.taskQueue.maxConcurrentOperationCount = 10;
56
+        self.rebindProgressDict = [NSMutableDictionary dictionary];
57
+        self.rebindUploadProgressDict = [NSMutableDictionary dictionary];
56
     }
58
     }
57
     
59
     
58
     return self;
60
     return self;
87
     
89
     
88
     @synchronized([RNFetchBlobNetwork class]) {
90
     @synchronized([RNFetchBlobNetwork class]) {
89
         [self.requestsTable setObject:request forKey:taskId];
91
         [self.requestsTable setObject:request forKey:taskId];
92
+        [self checkProgressConfig];
90
     }
93
     }
91
 }
94
 }
92
 
95
 
96
+- (void) checkProgressConfig {
97
+    //reconfig progress
98
+    [self.rebindProgressDict enumerateKeysAndObjectsUsingBlock:^(NSString * _Nonnull key, RNFetchBlobProgress * _Nonnull config, BOOL * _Nonnull stop) {
99
+        [self enableProgressReport:key config:config];
100
+    }];
101
+    [self.rebindProgressDict removeAllObjects];
102
+    
103
+    //reconfig uploadProgress
104
+    [self.rebindUploadProgressDict enumerateKeysAndObjectsUsingBlock:^(NSString * _Nonnull key, RNFetchBlobProgress * _Nonnull config, BOOL * _Nonnull stop) {
105
+        [self enableUploadProgress:key config:config];
106
+    }];
107
+    [self.rebindUploadProgressDict removeAllObjects];
108
+}
109
+
93
 - (void) enableProgressReport:(NSString *) taskId config:(RNFetchBlobProgress *)config
110
 - (void) enableProgressReport:(NSString *) taskId config:(RNFetchBlobProgress *)config
94
 {
111
 {
95
     if (config) {
112
     if (config) {
96
         @synchronized ([RNFetchBlobNetwork class]) {
113
         @synchronized ([RNFetchBlobNetwork class]) {
97
-            [self.requestsTable objectForKey:taskId].progressConfig = config;
114
+            if (![self.requestsTable objectForKey:taskId]) {
115
+                [self.rebindProgressDict setValue:config forKey:taskId];
116
+            } else {
117
+                [self.requestsTable objectForKey:taskId].progressConfig = config;
118
+            }
98
         }
119
         }
99
     }
120
     }
100
 }
121
 }
103
 {
124
 {
104
     if (config) {
125
     if (config) {
105
         @synchronized ([RNFetchBlobNetwork class]) {
126
         @synchronized ([RNFetchBlobNetwork class]) {
106
-            [self.requestsTable objectForKey:taskId].uploadProgressConfig = config;
127
+            if (![self.requestsTable objectForKey:taskId]) {
128
+                [self.rebindUploadProgressDict setValue:config forKey:taskId];
129
+            } else {
130
+                [self.requestsTable objectForKey:taskId].uploadProgressConfig = config;
131
+            }
107
         }
132
         }
108
     }
133
     }
109
 }
134
 }