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

Commit 5b04a2a

Browse files
committed
Add progress report support for IOS #1
1 parent 13bb6f0 commit 5b04a2a

File tree

6 files changed

+376
-49
lines changed

6 files changed

+376
-49
lines changed

src/index.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,15 @@
33
* @version 0.3.3
44
*/
55

6-
import { NativeModules } from 'react-native'
7-
import { DeviceEventEmitter } from 'react-native';
8-
import base64 from 'base-64'
6+
import {
7+
NativeModules,
8+
DeviceEventEmitter,
9+
NativeAppEventEmitter,
10+
Platform,
11+
} from 'react-native'
912

13+
import base64 from 'base-64'
14+
const emitter = (Platform.OS === 'android' ? DeviceEventEmitter : NativeAppEventEmitter)
1015
const RNFetchBlob = NativeModules.RNFetchBlob
1116

1217
// Show warning if native module not detected
@@ -27,7 +32,7 @@ const fetch = (...args) => {
2732

2833
let [method, url, headers, body] = [...args]
2934
let nativeMethodName = Array.isArray(body) ? 'fetchBlobForm' : 'fetchBlob'
30-
let handle = DeviceEventEmitter.addListener('RNFetchBlobProgress', (e) => {
35+
let subscription = emitter.addListener('RNFetchBlobProgress', (e) => {
3136
if(e.taskId === taskId && promise.onProgress) {
3237
promise.onProgress(e.written, e.total)
3338
}
@@ -36,7 +41,7 @@ const fetch = (...args) => {
3641
RNFetchBlob[nativeMethodName](taskId, method, url, headers || {}, body, (err, ...data) => {
3742

3843
// task done, remove event listener
39-
handle.remove()
44+
subscription.remove()
4045

4146
if(err)
4247
reject(new Error(err, ...data))

src/ios/RNFetchBlob.xcodeproj/project.pbxproj

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,22 @@
55
};
66
objectVersion = 46;
77
objects = {
8+
89
/* Begin PBXBuildFile section */
910
A15C30141CD25C330074CB35 /* RNFetchBlob.m in Sources */ = {isa = PBXBuildFile; fileRef = A15C30131CD25C330074CB35 /* RNFetchBlob.m */; };
1011
A166D1AA1CE0647A00273590 /* RNFetchBlob.h in Sources */ = {isa = PBXBuildFile; fileRef = A15C30111CD25C330074CB35 /* RNFetchBlob.h */; };
1112
/* End PBXBuildFile section */
1213

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+
1324
/* Begin PBXCopyFilesBuildPhase section */
1425
A15C300C1CD25C330074CB35 /* CopyFiles */ = {
1526
isa = PBXCopyFilesBuildPhase;
@@ -26,7 +37,7 @@
2637
A15C300E1CD25C330074CB35 /* libRNFetchBlob.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libRNFetchBlob.a; sourceTree = BUILT_PRODUCTS_DIR; };
2738
A15C30111CD25C330074CB35 /* RNFetchBlob.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = RNFetchBlob.h; path = RNFetchBlob/RNFetchBlob.h; sourceTree = "<group>"; };
2839
A15C30131CD25C330074CB35 /* RNFetchBlob.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = RNFetchBlob.m; path = RNFetchBlob/RNFetchBlob.m; sourceTree = "<group>"; };
29-
ADC1D945EE804D3DA47CF622 /* RNFetchBlob.xcodeproj */ = {isa = PBXFileReference; name = "RNFetchBlob.xcodeproj"; path = "../../node_modules/react-native-fetch-blob/ios/RNFetchBlob.xcodeproj"; sourceTree = "<group>"; fileEncoding = undefined; lastKnownFileType = wrapper.pb-project; explicitFileType = undefined; includeInIndex = 0; };
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>"; };
3041
/* End PBXFileReference section */
3142

3243
/* Begin PBXFrameworksBuildPhase section */
@@ -40,6 +51,14 @@
4051
/* End PBXFrameworksBuildPhase section */
4152

4253
/* Begin PBXGroup section */
54+
8BD9ABDFAF76406291A798F2 /* Libraries */ = {
55+
isa = PBXGroup;
56+
children = (
57+
ADC1D945EE804D3DA47CF622 /* RNFetchBlob.xcodeproj */,
58+
);
59+
name = Libraries;
60+
sourceTree = "<group>";
61+
};
4362
A15C30051CD25C330074CB35 = {
4463
isa = PBXGroup;
4564
children = (
@@ -58,13 +77,12 @@
5877
name = Products;
5978
sourceTree = "<group>";
6079
};
61-
8BD9ABDFAF76406291A798F2 /* Libraries */ = {
80+
A1BAA8981CF415DF003A9374 /* Products */ = {
6281
isa = PBXGroup;
6382
children = (
64-
ADC1D945EE804D3DA47CF622 /* RNFetchBlob.xcodeproj */,
83+
A1BAA89F1CF415DF003A9374 /* libRNFetchBlob.a */,
6584
);
66-
name = Libraries;
67-
path = "";
85+
name = Products;
6886
sourceTree = "<group>";
6987
};
7088
/* End PBXGroup section */
@@ -111,13 +129,29 @@
111129
mainGroup = A15C30051CD25C330074CB35;
112130
productRefGroup = A15C300F1CD25C330074CB35 /* Products */;
113131
projectDirPath = "";
132+
projectReferences = (
133+
{
134+
ProductGroup = A1BAA8981CF415DF003A9374 /* Products */;
135+
ProjectRef = ADC1D945EE804D3DA47CF622 /* RNFetchBlob.xcodeproj */;
136+
},
137+
);
114138
projectRoot = "";
115139
targets = (
116140
A15C300D1CD25C330074CB35 /* RNFetchBlob */,
117141
);
118142
};
119143
/* End PBXProject section */
120144

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+
121155
/* Begin PBXSourcesBuildPhase section */
122156
A15C300A1CD25C330074CB35 /* Sources */ = {
123157
isa = PBXSourcesBuildPhase;
@@ -225,6 +259,7 @@
225259
"$(SRCROOT)/../../react-native/React/**",
226260
"$(SRCROOT)/../../node_modules/react-native/React/**",
227261
"$(SRCROOT)/../../node_modules/react-native-fetch-blob/ios/RNFetchBlob",
262+
"$(SRCROOT)/../../RNFetchBlobTest/node_modules/react-native/**",
228263
);
229264
OTHER_LDFLAGS = "-ObjC";
230265
PRODUCT_NAME = "$(TARGET_NAME)";
@@ -244,6 +279,7 @@
244279
"$(SRCROOT)/../../react-native/React/**",
245280
"$(SRCROOT)/../../node_modules/react-native/React/**",
246281
"$(SRCROOT)/../../node_modules/react-native-fetch-blob/ios/RNFetchBlob",
282+
"$(SRCROOT)/../../RNFetchBlobTest/node_modules/react-native/**",
247283
);
248284
OTHER_LDFLAGS = "-ObjC";
249285
PRODUCT_NAME = "$(TARGET_NAME)";

src/ios/RNFetchBlob/RNFetchBlob.h

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,42 @@
11
//
22
// RNFetchBlob.h
33
//
4-
// Created by suzuri04x2 on 2016/4/28.
5-
// Copyright © 2016年 Facebook. All rights reserved.
4+
// Created by wkh237 on 2016/4/28.
65
//
76

87
#ifndef RNFetchBlob_h
98
#define RNFetchBlob_h
10-
9+
#import <Foundation/Foundation.h>
1110
#import "RCTBridgeModule.h"
1211

1312
@interface RNFetchBlob : NSObject <RCTBridgeModule>
1413

1514
@end
1615

17-
@interface FetchBlobUtils : NSObject
16+
@interface FetchBlobUtils : NSObject <NSURLConnectionDelegate, NSURLConnectionDataDelegate> {
17+
18+
NSString * taskId;
19+
int expectedBytes;
20+
int receivedBytes;
21+
NSMutableData * respData;
22+
RCTResponseSenderBlock callback;
23+
RCTBridge * bridge;
24+
}
25+
@property (nonatomic) NSString * taskId;
26+
@property (nonatomic) int expectedBytes;
27+
@property (nonatomic) int receivedBytes;
28+
@property (nonatomic) NSMutableData * respData;
29+
@property (nonatomic) RCTResponseSenderBlock callback;
30+
@property (nonatomic) RCTBridge * bridge;
31+
32+
33+
- (id) init;
34+
- (id) delegate;
35+
- (void) sendRequest;
1836

19-
+ (void) onBlobResponse;
2037
+ (NSMutableDictionary *) normalizeHeaders;
2138

39+
2240
@end
2341

2442

0 commit comments

Comments
 (0)