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

Commit e48e6ca

Browse files
committed
Change #29 IOS implementation
1 parent 71adfa6 commit e48e6ca

File tree

5 files changed

+103
-20
lines changed

5 files changed

+103
-20
lines changed

src/ios/RNFetchBlob/RNFetchBlob.m

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,6 @@ - (NSDictionary *)constantsToExport
160160
if([body hasPrefix:self.filePathPrefix]) {
161161
NSString * orgPath = [body substringFromIndex:[self.filePathPrefix length]];
162162
[request setHTTPBodyStream: [NSInputStream inputStreamWithFileAtPath:orgPath ]];
163-
// blobData = [[NSData alloc] initWithContentsOfFile:orgPath];
164163
}
165164
// otherwise convert it as BASE64 data string
166165
else {

src/ios/RNFetchBlobNetwork.m

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,19 @@ - (void) sendRequest:(NSDictionary * _Nullable )options bridge:(RCTBridge * _Nu
7171

7272
NSString * path = [self.options valueForKey:CONFIG_FILE_PATH];
7373
NSString * ext = [self.options valueForKey:CONFIG_FILE_EXT];
74-
NSURLSessionConfiguration *defaultConfigObject = [NSURLSessionConfiguration defaultSessionConfiguration];
75-
NSURLSession * session = [NSURLSession sessionWithConfiguration:defaultConfigObject delegate:self delegateQueue:taskQueue];
74+
NSURLSession * session;
7675

77-
// NSURLSession * session = [NSURLSession sharedSession];
76+
// the session trust any SSL certification
77+
if([options valueForKey:CONFIG_TRUSTY] != nil)
78+
{
79+
NSURLSessionConfiguration *defaultConfigObject = [NSURLSessionConfiguration defaultSessionConfiguration];
80+
session = [NSURLSession sessionWithConfiguration:defaultConfigObject delegate:self delegateQueue:taskQueue];
81+
}
82+
// the session validates SSL certification, self-signed certification will be aborted
83+
else
84+
{
85+
session = [NSURLSession sharedSession];
86+
}
7887

7988
// file will be stored at a specific path
8089
if( path != nil) {
@@ -210,10 +219,10 @@ - (void) URLSessionDidFinishEventsForBackgroundURLSession:(NSURLSession *)sessio
210219

211220
- (void) URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didReceiveChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition, NSURLCredential * _Nullable))completionHandler
212221
{
213-
if([options valueForKey:CONFIG_TRUSTY] == YES)
222+
if([options valueForKey:CONFIG_TRUSTY] != nil)
214223
completionHandler(NSURLSessionAuthChallengeUseCredential, [NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust]);
215224
else
216-
RCTLogError(@"counld not create connection with an unstrusted SSL certification, if you're going to create connection anyway, add `trusty:true` to RNFetchBlob.config");
225+
RCTLogWarn(@"counld not create connection with an unstrusted SSL certification, if you're going to create connection anyway, add `trusty:true` to RNFetchBlob.config");
217226
}
218227

219228
@end

test/test-0.1.x-0.4.x.js

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -114,16 +114,3 @@ describe('Progress report test', (report, done) => {
114114
})
115115

116116
})
117-
118-
// FIXME : not yet supported
119-
// describe('Large file download test', (report, done) => {
120-
// let received = 0
121-
// RNFetchBlob.fetch('GET', `${TEST_SERVER_URL}/public/22mb-dummy`, {
122-
// Authorization : 'Bearer abde123eqweje'
123-
// })
124-
// .then((resp) => {
125-
// report(<Assert key="not supported" expect={true} actual={false}/>)
126-
// done()
127-
// })
128-
129-
// })

test/test-0.5.3.js

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
import RNTest from './react-native-testkit/'
2+
import React from 'react'
3+
import RNFetchBlob from 'react-native-fetch-blob'
4+
5+
import {
6+
StyleSheet,
7+
Text,
8+
View,
9+
ScrollView,
10+
Platform,
11+
Dimensions,
12+
Image,
13+
} from 'react-native';
14+
15+
const fs = RNFetchBlob.fs
16+
const { Assert, Comparer, Info, prop } = RNTest
17+
const describe = RNTest.config({
18+
group : '0.5.3',
19+
run : true,
20+
expand : false,
21+
})
22+
const { TEST_SERVER_URL_SSL, FILENAME, DROPBOX_TOKEN, styles } = prop()
23+
24+
let prefix = ((Platform.OS === 'android') ? 'file://' : '')
25+
26+
27+
describe('GET request with params', (report, done) => {
28+
let time = Date.now()
29+
RNFetchBlob
30+
.config({ fileCache : true, trusty : true })
31+
.fetch('GET', `${TEST_SERVER_URL_SSL}/params?time=${time}&name=RNFetchBlobParams&lang=中文`)
32+
.then((resp) => {
33+
let file = resp.path()
34+
return RNFetchBlob.fs.readStream(resp.path(), 'utf8')
35+
})
36+
.then((stream) => {
37+
let result = ''
38+
stream.open()
39+
stream.onData((chunk) => {
40+
result += chunk
41+
})
42+
stream.onEnd(() => {
43+
result = JSON.parse(result)
44+
report(<Assert key="param#1 should correct"
45+
expect={parseInt(time)}
46+
actual={parseInt(result.time)}/>,
47+
<Assert key="param#2 should correct"
48+
expect={'RNFetchBlobParams'}
49+
actual={result.name}/>,
50+
<Assert key="param contains unicode data should correct"
51+
expect={'中文'}
52+
actual={result.lang}/>)
53+
done()
54+
})
55+
})
56+
})
57+
58+
59+
describe('POST request with params', (report, done) => {
60+
let time = Date.now()
61+
RNFetchBlob.config({ fileCache : true, trusty : true })
62+
.fetch('POST', `${TEST_SERVER_URL_SSL}/params?time=${time}&name=RNFetchBlobParams&lang=中文`)
63+
.then((resp) => {
64+
let file = resp.path()
65+
return RNFetchBlob.fs.readStream(resp.path(), 'utf8')
66+
})
67+
.then((stream) => {
68+
let result = ''
69+
stream.open()
70+
stream.onData((chunk) => {
71+
result += chunk
72+
})
73+
stream.onEnd(() => {
74+
result = JSON.parse(result)
75+
report(<Assert key="param#1 should correct"
76+
expect={parseInt(time)}
77+
actual={parseInt(result.time)}/>,
78+
<Assert key="param#2 should correct"
79+
expect={'RNFetchBlobParams'}
80+
actual={result.name}/>,
81+
<Assert key="param contains unicode data should correct"
82+
expect={'中文'}
83+
actual={result.lang}/>)
84+
done()
85+
})
86+
})
87+
})

test/test-init.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,5 +54,6 @@ describe('GET image from server', (report, done) => {
5454
require('./test-0.1.x-0.4.x')
5555
require('./test-0.5.1')
5656
require('./test-0.5.2')
57+
require('./test-0.5.3')
5758
require('./test-fs')
58-
require('./test-android')
59+
// require('./test-android')

0 commit comments

Comments
 (0)