Skip to content

Commit 29c50b8

Browse files
iOS UIWebView is deprecated #47
1 parent 656531c commit 29c50b8

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
@@ -34,7 +34,7 @@ export function disableSSLPinning() {
3434

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

37-
function AFSuccess(resolve, task: NSURLSessionDataTask, data: NSDictionary<string, any> & NSData & NSArray<any>) {
37+
function AFSuccess(resolve, task: NSURLSessionDataTask, data?: NSDictionary<string, any> & NSData & NSArray<any>) {
3838
let content: any;
3939
if (data && data.class) {
4040
if (data.enumerateKeysAndObjectsUsingBlock || (<any>data) instanceof NSArray) {
@@ -117,19 +117,34 @@ export function request(opts: Https.HttpsRequestOptions): Promise<Https.HttpsRes
117117

118118
manager.requestSerializer.timeoutInterval = opts.timeout ? opts.timeout : 10;
119119

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

134149
} catch (error) {
135150
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)