Skip to content

Commit c585dd4

Browse files
Merge branch 'master' into master
2 parents 07653e8 + 29c50b8 commit c585dd4

File tree

8 files changed

+400
-378
lines changed

8 files changed

+400
-378
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
### The definitive way to hit HTTP based APIs in Nativescript.
1818
Easily integrate the most reliable native networking libraries with the latest and greatest HTTPS security features.
1919

20+
> Plugin version 2.0.0 bumps `AFNetworking` on iOS to [4.0.0](https://github.com/AFNetworking/AFNetworking/releases/tag/4.0.0) which no longer relies on `UIWebView`. Make sure to run `pod repo update` to get the latest `AFNetworking` pod on your development machine.
21+
2022
#### A drop-in replacement for the [default http module](https://docs.nativescript.org/cookbook/http#get-response-status-code).
2123

2224
## Features

demo/app/App_Resources/iOS/build.xcconfig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@
33
// CODE_SIGN_IDENTITY = iPhone Distribution
44
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
55
ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage;
6+
7+
DEVELOPMENT_TEAM = 8Q5F6M3TNS

demo/app/main-page.ts

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -43,21 +43,22 @@ export function postHttpbin() {
4343
}
4444

4545
export function postHttpbinWithUTF8() {
46-
Https.request(
47-
{
48-
url: 'https://httpbin.org/post',
49-
method: 'POST',
50-
body: {"foo": "bar", "baz": undefined, "plaz": null},
51-
headers: {
52-
'Content-Type': "application/json; charset=utf-8"
53-
}
54-
})
55-
.then(response => console.log('Https.request response', response))
56-
.catch(error => {
57-
console.error('Https.request error', error);
58-
dialogs.alert(error);
59-
});
60-
}
46+
Https.request(
47+
{
48+
url: 'https://httpbin.org/post',
49+
method: 'POST',
50+
body: {"foo": "bar", "baz": undefined, "plaz": null},
51+
headers: {
52+
'Content-Type': "application/json; charset=utf-8",
53+
'X-testing': "ok"
54+
}
55+
})
56+
.then(response => console.log('Https.request response', response))
57+
.catch(error => {
58+
console.error('Https.request error', error);
59+
dialogs.alert(error);
60+
});
61+
}
6162

6263
export function getHttpbin() {
6364
getRequest('https://httpbin.org/get');

src/https.ios.ts

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export function disableSSLPinning() {
3737

3838
console.info('nativescript-https > Disabled SSL pinning by default');
3939

40-
function AFSuccess(resolve, task: NSURLSessionDataTask, data: NSDictionary<string, any> & NSData & NSArray<any>) {
40+
function AFSuccess(resolve, task: NSURLSessionDataTask, data?: NSDictionary<string, any> & NSData & NSArray<any>) {
4141
let content = getData(data);
4242
resolve({task, content});
4343
}
@@ -110,19 +110,34 @@ export function request(opts: Https.HttpsRequestOptions): Promise<Https.HttpsRes
110110

111111
manager.requestSerializer.timeoutInterval = opts.timeout ? opts.timeout : 10;
112112

113-
let methods = {
114-
'GET': 'GETParametersSuccessFailure',
115-
'POST': 'POSTParametersSuccessFailure',
116-
'PUT': 'PUTParametersSuccessFailure',
117-
'DELETE': 'DELETEParametersSuccessFailure',
118-
'PATCH': 'PATCHParametersSuccessFailure',
119-
'HEAD': 'HEADParametersSuccessFailure',
120-
};
121-
manager[methods[opts.method]](opts.url, dict, function success(task: NSURLSessionDataTask, data: any) {
113+
const headers = null;
114+
115+
const success = (task: NSURLSessionDataTask, data?: any) => {
122116
AFSuccess(resolve, task, data);
123-
}, function failure(task, error) {
117+
};
118+
119+
const failure = (task, error) => {
124120
AFFailure(resolve, reject, task, error);
125-
});
121+
};
122+
123+
const progress = (progress: NSProgress) => {
124+
// console.log("Finished?: " + progress.finished);
125+
};
126+
127+
if (opts.method === "GET") {
128+
manager.GETParametersHeadersProgressSuccessFailure(opts.url, dict, headers, progress, success, failure);
129+
} else if (opts.method === "POST") {
130+
manager.POSTParametersHeadersProgressSuccessFailure(opts.url, dict, headers, progress, success, failure);
131+
} else if (opts.method === "PUT") {
132+
manager.PUTParametersHeadersSuccessFailure(opts.url, dict, headers, success, failure);
133+
} else if (opts.method === "DELETE") {
134+
manager.DELETEParametersHeadersSuccessFailure(opts.url, dict, headers, success, failure);
135+
} else if (opts.method === "PATCH") {
136+
manager.PATCHParametersHeadersSuccessFailure(opts.url, dict, headers, success, failure);
137+
} else if (opts.method === "HEAD") {
138+
manager.HEADParametersHeadersSuccessFailure(opts.url, dict, headers, success, failure);
139+
}
140+
126141

127142
} catch (error) {
128143
reject(error);

src/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "nativescript-https",
3-
"version": "1.3.0",
3+
"version": "2.0.0",
44
"description": "Secure HTTP client with SSL pinning for Nativescript - iOS/Android.",
55
"main": "https",
66
"typings": "index.d.ts",
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
dependencies {
2-
implementation 'com.squareup.okhttp3:okhttp:3.12.1'
2+
implementation 'com.squareup.okhttp3:okhttp:3.14.7'
33
}

src/platforms/ios/Podfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
pod 'AFNetworking', '~> 3.2.1'
1+
pod 'AFNetworking', '~> 4.0'

0 commit comments

Comments
 (0)