Skip to content

Commit 418ec2d

Browse files
Merge pull request #42 from EddyVerbruggen/master
Bump AFNetworking and add opt-in support for large HTTP responses on Android
2 parents 7eb8a39 + 721acd5 commit 418ec2d

21 files changed

+3851
-72
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ src/*.d.ts
1313
seed-tests/seed-copy/**/*.*
1414
seed-tests/seed-copy-new-git-repo/**/*.*
1515
!demo/karma.conf.js
16+
!demo/webpack.config.js
1617
!demo/app/tests/*.js
1718
demo/*.d.ts
1819
!demo/references.d.ts

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,10 @@ You can bypass this behavior by adding the following to your projects `Info.plis
114114
```
115115
> This plugin **does not** add `NSAllowsArbitraryLoads` to your projects `Info.plist` for you.
116116
117+
## `Android` troubleshooting
118+
If you app crashes with a message that it's doing too much networkin on the main thread,
119+
then pass the option `allowLargeResponse` with value `true` to the `request` function.
120+
117121
# Thanks
118122
Who | Why
119123
------------ | -------------
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// You can add custom settings here
22
// for example you can uncomment the following line to force distribution code signing
3-
// CODE_SIGN_IDENTITY = iPhone Distribution
3+
// CODE_SIGN_IDENTITY = iPhone Distribution
44
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
55
ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage;

demo/app/assets/httpbin.org.cer

1 Byte
Binary file not shown.

demo/app/main-page.ts

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,32 @@
1-
21
import * as Observable from 'tns-core-modules/data/observable'
32
import * as Page from 'tns-core-modules/ui/page'
43
import * as fs from 'tns-core-modules/file-system'
54
import * as dialogs from 'tns-core-modules/ui/dialogs'
65
import * as Https from 'nativescript-https'
76

8-
9-
107
export function onNavigatingTo(args: Page.NavigatedData) {
118
let page = args.object as Page.Page
129
page.bindingContext = Observable.fromObject({ enabled: false })
1310
}
1411

15-
function getRequest(url: string) {
12+
function getRequest(url: string, allowLargeResponse = false) {
13+
Https.request({
14+
url,
15+
method: 'GET',
16+
allowLargeResponse
17+
}).then(function(response) {
18+
console.log('Https.request response', response)
19+
}).catch(function(error) {
20+
console.error('Https.request error', error)
21+
dialogs.alert(error)
22+
})
23+
}
24+
25+
function postRequest(url: string, body: any) {
1626
Https.request({
17-
url, method: 'GET',
27+
url,
28+
method: 'POST',
29+
body
1830
}).then(function(response) {
1931
console.log('Https.request response', response)
2032
}).catch(function(error) {
@@ -23,7 +35,9 @@ function getRequest(url: string) {
2335
})
2436
}
2537

38+
export function postHttpbin() { postRequest('https://httpbin.org/post', {"foo": "bar", "baz": undefined, "plaz": null}) }
2639
export function getHttpbin() { getRequest('https://httpbin.org/get') }
40+
export function getHttpbinLargeResponse() { getRequest('https://httpbin.org/bytes/100000', true) }
2741
export function getMockbin() { getRequest('https://mockbin.com/request') }
2842

2943
export function enableSSLPinning(args: Observable.EventData) {

demo/app/main-page.xml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,14 @@
55

66
<StackLayout class="p-20">
77
<Label class="h1 text-center" color="{{ enabled ? 'green' : 'red' }}" text="{{ enabled ? 'Httpbin SSL Pinning Enabled' : 'SSL Pinning Disabled' }}" />
8-
<Button text="Httpbin" tap="getHttpbin" class="t-20 btn btn-primary btn-active" />
9-
<Button text="Mockbin" tap="getMockbin" class="t-20 btn btn-primary btn-active" />
8+
<Button text="GET Mockbin" tap="getMockbin" class="t-20 btn btn-primary btn-active" />
9+
<Button text="GET Httpbin" tap="getHttpbin" class="t-20 btn btn-primary btn-active" />
10+
<Button text="GET Httpbin (large response)" tap="getHttpbinLargeResponse" class="t-20 btn btn-primary btn-active" />
11+
<Button text="POST Httpbin " tap="postHttpbin" class="t-20 btn btn-primary btn-active" />
1012
<Button text="Enable Httpbin SSL Pinning" tap="enableSSLPinning" class="t-20 btn btn-primary btn-active" />
1113
<Button text="Disable SSL Pinning" tap="disableSSLPinning" class="t-20 btn btn-primary btn-active" />
14+
<Label text="Here's a spinner to show the main thread is not blocked by network IO" textWrap="true" class="m-20"/>
15+
<ActivityIndicator busy="true" />
1216
</StackLayout>
1317

1418
</Page>

demo/nsconfig.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"useLegacyWorkflow": false
3+
}

demo/package.json

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,17 @@
22
"nativescript": {
33
"id": "org.nativescript.demo",
44
"tns-android": {
5-
"version": "5.1.0"
5+
"version": "5.4.0"
6+
},
7+
"tns-ios": {
8+
"version": "5.4.0"
69
}
710
},
811
"dependencies": {
912
"nativescript-https": "file:../src",
1013
"nativescript-theme-core": "^1.0.4",
1114
"nativescript-unit-test-runner": "^0.3.4",
12-
"tns-core-modules": "^5.1.0"
15+
"tns-core-modules": "~5.4.0"
1316
},
1417
"devDependencies": {
1518
"jasmine-core": "^2.5.2",
@@ -18,10 +21,10 @@
1821
"karma-nativescript-launcher": "^0.4.0",
1922
"nativescript-css-loader": "~0.26.1",
2023
"nativescript-dev-typescript": "~0.7.4",
21-
"nativescript-dev-webpack": "~0.17.0",
22-
"tns-platform-declarations": "^5.1.0",
24+
"nativescript-dev-webpack": "0.24.1",
25+
"tns-platform-declarations": "~5.4.0",
2326
"tslint": "~5.11.0",
24-
"typescript": "~2.8.2"
27+
"typescript": "~2.9.0"
2528
},
2629
"scripts": {
2730
"build.plugin": "cd ../src && npm run build",

demo/tsconfig.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,9 @@
3131
}
3232
},
3333
"include": [
34-
"../src",
3534
"**/*"
3635
],
3736
"exclude": [
38-
"../src/node_modules",
3937
"node_modules",
4038
"platforms"
4139
],

0 commit comments

Comments
 (0)