@maccesar/titools 2.2.4 → 2.2.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +23 -23
- package/agents/ti-pro.md +17 -17
- package/lib/commands/update.js +6 -14
- package/lib/downloader.js +17 -2
- package/package.json +1 -1
- package/skills/alloy-guides/SKILL.md +31 -31
- package/skills/alloy-guides/references/CONCEPTS.md +3 -3
- package/skills/alloy-guides/references/CONTROLLERS.md +1 -1
- package/skills/alloy-guides/references/MODELS.md +6 -6
- package/skills/alloy-guides/references/VIEWS_WITHOUT_CONTROLLERS.md +1 -1
- package/skills/alloy-guides/references/VIEWS_XML.md +1 -1
- package/skills/alloy-guides/references/WIDGETS.md +1 -1
- package/skills/alloy-howtos/SKILL.md +27 -27
- package/skills/alloy-howtos/references/best_practices.md +9 -9
- package/skills/alloy-howtos/references/cli_reference.md +14 -14
- package/skills/alloy-howtos/references/config_files.md +16 -16
- package/skills/alloy-howtos/references/custom_tags.md +16 -16
- package/skills/alloy-howtos/references/debugging_troubleshooting.md +11 -15
- package/skills/alloy-howtos/references/samples.md +19 -19
- package/skills/purgetss/SKILL.md +11 -1
- package/skills/purgetss/references/animation-system.md +1 -1
- package/skills/purgetss/references/cli-commands.md +3 -3
- package/skills/purgetss/references/customization-deep-dive.md +1 -1
- package/skills/purgetss/references/dynamic-component-creation.md +1 -1
- package/skills/purgetss/references/icon-fonts.md +4 -0
- package/skills/purgetss/references/installation-setup.md +8 -1
- package/skills/purgetss/references/migration-guide.md +4 -0
- package/skills/purgetss/references/tikit-components.md +193 -204
- package/skills/purgetss/references/ui-ux-design.md +1 -1
- package/skills/ti-expert/SKILL.md +78 -118
- package/skills/ti-expert/references/alloy-builtins.md +18 -18
- package/skills/ti-expert/references/alloy-structure.md +21 -21
- package/skills/ti-expert/references/anti-patterns.md +15 -15
- package/skills/ti-expert/references/cli-expert.md +15 -15
- package/skills/ti-expert/references/code-conventions.md +38 -38
- package/skills/ti-expert/references/contracts.md +8 -8
- package/skills/ti-expert/references/controller-patterns.md +14 -14
- package/skills/ti-expert/references/error-handling.md +11 -11
- package/skills/ti-expert/references/examples.md +12 -12
- package/skills/ti-expert/references/migration-patterns.md +24 -24
- package/skills/ti-expert/references/patterns.md +10 -10
- package/skills/ti-expert/references/performance-listview.md +16 -16
- package/skills/ti-expert/references/performance-optimization.md +41 -41
- package/skills/ti-expert/references/security-device.md +22 -22
- package/skills/ti-expert/references/security-fundamentals.md +19 -19
- package/skills/ti-expert/references/state-management.md +33 -33
- package/skills/ti-expert/references/testing-e2e-ci.md +25 -25
- package/skills/ti-expert/references/testing-unit.md +24 -24
- package/skills/ti-expert/references/theming.md +15 -15
- package/skills/ti-guides/SKILL.md +58 -60
- package/skills/ti-guides/references/advanced-data-and-images.md +33 -33
- package/skills/ti-guides/references/android-manifest.md +15 -15
- package/skills/ti-guides/references/app-distribution.md +70 -166
- package/skills/ti-guides/references/application-frameworks.md +96 -114
- package/skills/ti-guides/references/cli-reference.md +294 -294
- package/skills/ti-guides/references/coding-best-practices.md +42 -33
- package/skills/ti-guides/references/commonjs-advanced.md +57 -51
- package/skills/ti-guides/references/hello-world.md +36 -36
- package/skills/ti-guides/references/hyperloop-native-access.md +66 -66
- package/skills/ti-guides/references/javascript-primer.md +83 -101
- package/skills/ti-guides/references/reserved-words.md +9 -9
- package/skills/ti-guides/references/resources.md +75 -83
- package/skills/ti-guides/references/style-and-conventions.md +35 -28
- package/skills/ti-guides/references/tiapp-config.md +110 -74
- package/skills/ti-howtos/SKILL.md +88 -92
- package/skills/ti-howtos/references/android-platform-deep-dives.md +104 -104
- package/skills/ti-howtos/references/automation-fastlane-appium.md +39 -39
- package/skills/ti-howtos/references/buffer-codec-streams.md +60 -60
- package/skills/ti-howtos/references/cross-platform-development.md +115 -136
- package/skills/ti-howtos/references/debugging-profiling.md +167 -181
- package/skills/ti-howtos/references/extending-titanium.md +121 -121
- package/skills/ti-howtos/references/google-maps-v2.md +84 -82
- package/skills/ti-howtos/references/ios-map-kit.md +65 -60
- package/skills/ti-howtos/references/ios-platform-deep-dives.md +123 -123
- package/skills/ti-howtos/references/local-data-sources.md +79 -78
- package/skills/ti-howtos/references/location-and-maps.md +116 -120
- package/skills/ti-howtos/references/media-apis.md +87 -86
- package/skills/ti-howtos/references/notification-services.md +250 -260
- package/skills/ti-howtos/references/remote-data-sources.md +98 -93
- package/skills/ti-howtos/references/tutorials.md +226 -216
- package/skills/ti-howtos/references/using-modules.md +73 -102
- package/skills/ti-howtos/references/web-content-integration.md +101 -103
- package/skills/ti-howtos/references/webpack-build-pipeline.md +52 -44
- package/skills/ti-ui/SKILL.md +85 -85
- package/skills/ti-ui/references/accessibility-deep-dive.md +57 -57
- package/skills/ti-ui/references/animation-and-matrices.md +79 -79
- package/skills/ti-ui/references/application-structures.md +96 -99
- package/skills/ti-ui/references/custom-fonts-styling.md +99 -99
- package/skills/ti-ui/references/event-handling.md +58 -58
- package/skills/ti-ui/references/gestures.md +62 -64
- package/skills/ti-ui/references/icons-and-splash-screens.md +88 -88
- package/skills/ti-ui/references/layouts-and-positioning.md +87 -97
- package/skills/ti-ui/references/listviews-and-performance.md +107 -107
- package/skills/ti-ui/references/orientation.md +87 -88
- package/skills/ti-ui/references/platform-ui-android.md +87 -81
- package/skills/ti-ui/references/platform-ui-ios.md +63 -61
- package/skills/ti-ui/references/scrolling-views.md +29 -29
- package/skills/ti-ui/references/tableviews.md +56 -56
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
# Remote
|
|
1
|
+
# Remote data sources
|
|
2
2
|
|
|
3
|
-
## 1. HTTPClient and
|
|
3
|
+
## 1. HTTPClient and request lifecycle
|
|
4
4
|
|
|
5
|
-
### Basic
|
|
6
|
-
`Ti.Network.HTTPClient` mirrors XHR (XMLHttpRequest) API. Always handle both success and error
|
|
5
|
+
### Basic pattern
|
|
6
|
+
`Ti.Network.HTTPClient` mirrors the XHR (XMLHttpRequest) API. Always handle both success and error paths.
|
|
7
7
|
|
|
8
8
|
```javascript
|
|
9
9
|
const xhr = Ti.Network.createHTTPClient({
|
|
10
10
|
onload: (e) => {
|
|
11
|
-
// this.responseText - raw text (
|
|
11
|
+
// this.responseText - raw text (JSON/text)
|
|
12
12
|
// this.responseXML - XML document (including SOAP)
|
|
13
13
|
// this.responseData - binary data (Blob)
|
|
14
14
|
Ti.API.debug(xhr.responseText);
|
|
@@ -22,13 +22,13 @@ xhr.open('GET', 'https://api.example.com/data');
|
|
|
22
22
|
xhr.send();
|
|
23
23
|
```
|
|
24
24
|
|
|
25
|
-
### HTTP
|
|
25
|
+
### HTTP methods
|
|
26
26
|
- GET: `xhr.open('GET', url)` then `xhr.send()`
|
|
27
27
|
- POST: `xhr.open('POST', url)` then `xhr.send({key: 'value'})`
|
|
28
|
-
- PUT/DELETE/PATCH:
|
|
28
|
+
- PUT/DELETE/PATCH: all supported (PATCH since 4.1.0 on Android)
|
|
29
29
|
|
|
30
|
-
### Setting
|
|
31
|
-
|
|
30
|
+
### Setting headers
|
|
31
|
+
Headers must be set after `open()` but before `send()`.
|
|
32
32
|
|
|
33
33
|
```javascript
|
|
34
34
|
const client = Ti.Network.createHTTPClient();
|
|
@@ -38,17 +38,17 @@ client.setRequestHeader('Authorization', `Bearer ${token}`);
|
|
|
38
38
|
client.send('data');
|
|
39
39
|
```
|
|
40
40
|
|
|
41
|
-
### XHR
|
|
41
|
+
### XHR lifecycle states
|
|
42
42
|
Monitor with `onreadystatechange`:
|
|
43
|
-
- `UNSENT` -
|
|
43
|
+
- `UNSENT` - object constructed
|
|
44
44
|
- `OPENED` - `open()` called successfully
|
|
45
|
-
- `HEADERS_RECEIVED` -
|
|
46
|
-
- `LOADING` -
|
|
47
|
-
- `DONE` -
|
|
45
|
+
- `HEADERS_RECEIVED` - all redirects followed, headers received
|
|
46
|
+
- `LOADING` - response body being received
|
|
47
|
+
- `DONE` - transfer complete or error occurred
|
|
48
48
|
|
|
49
49
|
```javascript
|
|
50
50
|
xhr.onreadystatechange = (e) => {
|
|
51
|
-
switch(xhr.readyState) {
|
|
51
|
+
switch (xhr.readyState) {
|
|
52
52
|
case Ti.Network.HTTPClient.HEADERS_RECEIVED:
|
|
53
53
|
Ti.API.info(`Headers: ${xhr.getResponseHeader('Content-Type')}`);
|
|
54
54
|
break;
|
|
@@ -59,9 +59,9 @@ xhr.onreadystatechange = (e) => {
|
|
|
59
59
|
};
|
|
60
60
|
```
|
|
61
61
|
|
|
62
|
-
### Progress
|
|
63
|
-
- `onsendstream`:
|
|
64
|
-
- `ondatastream`:
|
|
62
|
+
### Progress monitoring
|
|
63
|
+
- `onsendstream`: upload progress (0.0-1.0)
|
|
64
|
+
- `ondatastream`: download progress (0.0-1.0)
|
|
65
65
|
|
|
66
66
|
```javascript
|
|
67
67
|
xhr.onsendstream = (e) => {
|
|
@@ -72,7 +72,7 @@ xhr.ondatastream = (e) => {
|
|
|
72
72
|
};
|
|
73
73
|
```
|
|
74
74
|
|
|
75
|
-
## 2. Working with JSON
|
|
75
|
+
## 2. Working with JSON data
|
|
76
76
|
|
|
77
77
|
### Receiving JSON
|
|
78
78
|
```javascript
|
|
@@ -83,15 +83,15 @@ xhr.onload = () => {
|
|
|
83
83
|
```
|
|
84
84
|
|
|
85
85
|
### Sending JSON
|
|
86
|
-
`send()`
|
|
86
|
+
`send()` stringifies objects for you.
|
|
87
87
|
|
|
88
88
|
```javascript
|
|
89
89
|
const postData = { title: 'My Post', body: 'Content' };
|
|
90
90
|
xhr.open('POST', 'http://blog.com/api/posts');
|
|
91
|
-
xhr.send(postData);
|
|
91
|
+
xhr.send(postData); // Auto-stringified
|
|
92
92
|
```
|
|
93
93
|
|
|
94
|
-
For GET
|
|
94
|
+
For GET query strings, stringify and encode yourself.
|
|
95
95
|
|
|
96
96
|
```javascript
|
|
97
97
|
const data = { search: 'titanium' };
|
|
@@ -100,13 +100,13 @@ xhr.open('GET', `http://api.com/search?q=${queryString}`);
|
|
|
100
100
|
xhr.send();
|
|
101
101
|
```
|
|
102
102
|
|
|
103
|
-
### Important
|
|
104
|
-
JSON cannot represent methods.
|
|
103
|
+
### Important limitation
|
|
104
|
+
JSON cannot represent methods. Stringifying Titanium objects returns an empty representation.
|
|
105
105
|
|
|
106
|
-
## 3. Working with XML
|
|
106
|
+
## 3. Working with XML data
|
|
107
107
|
|
|
108
108
|
### Parsing XML
|
|
109
|
-
Titanium provides XML DOM Level 2
|
|
109
|
+
Titanium provides XML DOM Level 2. If the response is XML and the server sends the correct Content-Type, Titanium auto-parses it.
|
|
110
110
|
|
|
111
111
|
```javascript
|
|
112
112
|
xhr.onload = () => {
|
|
@@ -121,19 +121,19 @@ xhr.onload = () => {
|
|
|
121
121
|
};
|
|
122
122
|
```
|
|
123
123
|
|
|
124
|
-
### Common DOM
|
|
125
|
-
- `getElementsByTagName(name)` -
|
|
126
|
-
- `item(index)` -
|
|
127
|
-
- `getAttribute(name)` -
|
|
128
|
-
- `textContent` / `nodeValue` -
|
|
124
|
+
### Common DOM methods
|
|
125
|
+
- `getElementsByTagName(name)` - returns array of nodes
|
|
126
|
+
- `item(index)` - selects a specific node from the array
|
|
127
|
+
- `getAttribute(name)` - gets an attribute value
|
|
128
|
+
- `textContent` / `nodeValue` - gets a leaf node value
|
|
129
129
|
|
|
130
|
-
### Important:
|
|
130
|
+
### Important: know your DTD
|
|
131
131
|
You must understand the XML structure (node hierarchy) to parse correctly. Use tools like apigee.com to inspect API responses.
|
|
132
132
|
|
|
133
|
-
## 4. File
|
|
133
|
+
## 4. File uploads and downloads
|
|
134
134
|
|
|
135
|
-
### File
|
|
136
|
-
Pass a Blob to `send()
|
|
135
|
+
### File upload
|
|
136
|
+
Pass a Blob to `send()`.
|
|
137
137
|
|
|
138
138
|
```javascript
|
|
139
139
|
Ti.Media.openPhotoGallery({
|
|
@@ -145,7 +145,7 @@ Ti.Media.openPhotoGallery({
|
|
|
145
145
|
});
|
|
146
146
|
xhr.open('POST', 'https://server.com/upload');
|
|
147
147
|
xhr.send({
|
|
148
|
-
file: event.media,
|
|
148
|
+
file: event.media, // Blob from gallery
|
|
149
149
|
username: 'user'
|
|
150
150
|
});
|
|
151
151
|
}
|
|
@@ -153,6 +153,7 @@ Ti.Media.openPhotoGallery({
|
|
|
153
153
|
```
|
|
154
154
|
|
|
155
155
|
For file uploads with actual file contents:
|
|
156
|
+
|
|
156
157
|
```javascript
|
|
157
158
|
const file = Ti.Filesystem.getFile(event.media.nativePath);
|
|
158
159
|
if (file.exists()) {
|
|
@@ -160,11 +161,11 @@ if (file.exists()) {
|
|
|
160
161
|
}
|
|
161
162
|
```
|
|
162
163
|
|
|
163
|
-
|
|
164
|
+
Note: when uploading from the photo gallery, `event.media` is a Blob. For filesystem uploads, use `Ti.Filesystem.getFile(path).read()` to get a Blob.
|
|
164
165
|
|
|
165
|
-
### File
|
|
166
|
+
### File download (cross-platform)
|
|
166
167
|
|
|
167
|
-
|
|
168
|
+
Option 1: write manually to the filesystem.
|
|
168
169
|
|
|
169
170
|
```javascript
|
|
170
171
|
const xhr = Ti.Network.createHTTPClient({
|
|
@@ -182,9 +183,8 @@ xhr.open('GET', 'http://example.com/image.png');
|
|
|
182
183
|
xhr.send();
|
|
183
184
|
```
|
|
184
185
|
|
|
185
|
-
|
|
186
|
+
Option 2 (iOS only): set `xhr.file` to save directly without buffering.
|
|
186
187
|
|
|
187
|
-
**iOS-only**: Use `xhr.file` to save downloads directly to a file without buffering in memory:
|
|
188
188
|
```javascript
|
|
189
189
|
xhr.file = Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory, 'download.zip');
|
|
190
190
|
```
|
|
@@ -203,24 +203,24 @@ xhr.file = Ti.Filesystem.getFile(
|
|
|
203
203
|
xhr.send();
|
|
204
204
|
```
|
|
205
205
|
|
|
206
|
-
### File
|
|
207
|
-
- `applicationDataDirectory` -
|
|
208
|
-
- `resourcesDirectory` -
|
|
209
|
-
- `tempDirectory` -
|
|
206
|
+
### File storage locations
|
|
207
|
+
- `applicationDataDirectory` - primary read/write location for app files
|
|
208
|
+
- `resourcesDirectory` - read-only app resources (writeable in simulator only)
|
|
209
|
+
- `tempDirectory` - temporary files, OS may delete when app closes
|
|
210
210
|
- `externalCacheDirectory` - Android SD card cache (check `isExternalStoragePresent()`)
|
|
211
|
-
- `applicationCacheDirectory` -
|
|
211
|
+
- `applicationCacheDirectory` - cache data, persists but OS may clean it up
|
|
212
212
|
|
|
213
213
|
## 5. Sockets
|
|
214
214
|
|
|
215
|
-
Titanium supports TCP
|
|
215
|
+
Titanium supports TCP sockets via `Ti.Network.Socket`.
|
|
216
216
|
|
|
217
|
-
### Creating a TCP
|
|
217
|
+
### Creating a TCP socket
|
|
218
218
|
|
|
219
219
|
```javascript
|
|
220
220
|
const socket = Ti.Network.Socket.createTCP({
|
|
221
221
|
host: 'example.com',
|
|
222
222
|
port: 80,
|
|
223
|
-
connected: function(e) {
|
|
223
|
+
connected: function (e) {
|
|
224
224
|
Ti.API.info('Socket connected');
|
|
225
225
|
// Write data
|
|
226
226
|
this.write(Ti.createBuffer({
|
|
@@ -235,77 +235,81 @@ const socket = Ti.Network.Socket.createTCP({
|
|
|
235
235
|
socket.connect();
|
|
236
236
|
```
|
|
237
237
|
|
|
238
|
-
### Socket
|
|
238
|
+
### Socket listening (Android/iOS)
|
|
239
239
|
To create a socket server that accepts connections:
|
|
240
|
+
|
|
240
241
|
```javascript
|
|
241
242
|
const listenSocket = Ti.Network.Socket.createTCP({
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
243
|
+
host: '127.0.0.1', // localhost
|
|
244
|
+
port: 40404,
|
|
245
|
+
accepted: (e) => {
|
|
246
|
+
Ti.API.info(`Incoming connection accepted: ${e.inbound}`);
|
|
247
|
+
e.inbound.close();
|
|
248
|
+
}
|
|
248
249
|
});
|
|
249
250
|
listenSocket.listen();
|
|
250
251
|
listenSocket.accept(); // Asynchronous, waits for next connection
|
|
251
252
|
```
|
|
252
253
|
|
|
253
|
-
|
|
254
|
+
Platform note: on iOS, `Ti.Platform.address` returns the WiFi interface address. On Android, only the loopback address (`127.0.0.1`) is available for listening sockets.
|
|
254
255
|
|
|
255
|
-
## 6. Dealing with SOAP
|
|
256
|
+
## 6. Dealing with SOAP web services
|
|
256
257
|
|
|
257
|
-
|
|
258
|
+
JSON is recommended, but you can consume legacy SOAP services by sending the XML envelope manually.
|
|
258
259
|
|
|
259
|
-
### Manual
|
|
260
|
+
### Manual approach (SOAP envelope)
|
|
260
261
|
```javascript
|
|
261
262
|
const client = Ti.Network.createHTTPClient();
|
|
262
263
|
client.onload = () => {
|
|
263
|
-
|
|
264
|
-
|
|
264
|
+
const doc = client.responseXML.documentElement;
|
|
265
|
+
// Parse the response XML manually
|
|
265
266
|
};
|
|
266
267
|
|
|
267
268
|
const soapRequest = "<?xml version=\"1.0\" encoding=\"UTF-8\"?> \n" +
|
|
268
|
-
"<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\"> \n" +
|
|
269
|
-
"<SOAP-ENV:Body> \n" +
|
|
270
|
-
" <GetUserDetailsReq> \n" +
|
|
271
|
-
" <SessionToken>XXXX</SessionToken> \n" +
|
|
272
|
-
" </GetUserDetailsReq> \n" +
|
|
273
|
-
"</SOAP-ENV:Body> \n" +
|
|
274
|
-
"</SOAP-ENV:Envelope>";
|
|
269
|
+
"<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\"> \n" +
|
|
270
|
+
"<SOAP-ENV:Body> \n" +
|
|
271
|
+
" <GetUserDetailsReq> \n" +
|
|
272
|
+
" <SessionToken>XXXX</SessionToken> \n" +
|
|
273
|
+
" </GetUserDetailsReq> \n" +
|
|
274
|
+
"</SOAP-ENV:Body> \n" +
|
|
275
|
+
"</SOAP-ENV:Envelope>";
|
|
275
276
|
|
|
276
277
|
client.open('POST', 'https://server.com/service.asmx');
|
|
277
278
|
client.setRequestHeader('Content-Type', 'text/xml; charset=utf-8');
|
|
278
279
|
client.send({ xml: soapRequest });
|
|
279
280
|
```
|
|
280
281
|
|
|
281
|
-
## 7. SSL
|
|
282
|
+
## 7. SSL certificate and SecurityManager
|
|
282
283
|
|
|
283
|
-
For
|
|
284
|
+
For SSL pinning, use the `securityManager` property.
|
|
284
285
|
|
|
285
|
-
### SSL
|
|
286
|
-
|
|
286
|
+
### SSL pinning (TiSDK 3.3.0+)
|
|
287
|
+
Pinning ensures the app only communicates with a server that presents a specific certificate.
|
|
287
288
|
|
|
288
289
|
```javascript
|
|
289
290
|
const xhr = Ti.Network.createHTTPClient({
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
291
|
+
validatesSecureCertificate: true,
|
|
292
|
+
// securityManager allows custom validation logic
|
|
293
|
+
securityManager: mySecurityModule
|
|
293
294
|
});
|
|
294
295
|
```
|
|
295
296
|
|
|
296
|
-
### SSL
|
|
297
|
+
### SSL certificate store (Android)
|
|
297
298
|
```javascript
|
|
298
299
|
const certificateStore = require('ti.certificatestore');
|
|
299
300
|
const httpClient = Ti.Network.createHTTPClient({
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
301
|
+
securityManager: certificateStore.createX509CertificatePinningSecurityManager([
|
|
302
|
+
{
|
|
303
|
+
url: 'https://api.example.com',
|
|
304
|
+
serverCertificate: 'api_cert.der'
|
|
305
|
+
}
|
|
306
|
+
])
|
|
304
307
|
});
|
|
305
308
|
```
|
|
306
309
|
|
|
307
310
|
### Android: addTrustManager
|
|
308
|
-
|
|
311
|
+
Use this for development environments or private networks with custom certs.
|
|
312
|
+
|
|
309
313
|
```javascript
|
|
310
314
|
const certificateStore = require('ti.certificatestore');
|
|
311
315
|
const xhr = Ti.Network.createHTTPClient();
|
|
@@ -313,22 +317,23 @@ const xhr = Ti.Network.createHTTPClient();
|
|
|
313
317
|
certificateStore.addCertificate('server.p12', 'password');
|
|
314
318
|
xhr.addTrustManager(certificateStore.getTrustManager());
|
|
315
319
|
|
|
316
|
-
xhr.open(
|
|
320
|
+
xhr.open('GET', url);
|
|
317
321
|
xhr.send();
|
|
318
322
|
```
|
|
319
|
-
|
|
323
|
+
|
|
324
|
+
## 8. CORS considerations for Mobile Web
|
|
320
325
|
|
|
321
326
|
For Mobile Web targets accessing cross-domain resources:
|
|
322
|
-
- Enable CORS headers on server
|
|
327
|
+
- Enable CORS headers on the server
|
|
323
328
|
- Or configure a proxy service
|
|
324
329
|
- Use custom `Ti.Network.httpURLFormatter`
|
|
325
330
|
|
|
326
|
-
## Best
|
|
331
|
+
## Best practices
|
|
327
332
|
|
|
328
|
-
1.
|
|
329
|
-
2.
|
|
330
|
-
3.
|
|
331
|
-
4.
|
|
332
|
-
5.
|
|
333
|
-
6.
|
|
334
|
-
7.
|
|
333
|
+
1. Set timeouts to prevent hanging requests.
|
|
334
|
+
2. Handle both `onload` and `onerror`.
|
|
335
|
+
3. Use progress callbacks for large file operations.
|
|
336
|
+
4. Save large downloads to disk using `file` (iOS) or `write()` to avoid memory exhaustion.
|
|
337
|
+
5. For complex JSON, validate schema before parsing.
|
|
338
|
+
6. For XML, test with real responses to verify node hierarchy.
|
|
339
|
+
7. Use `onsendstream` and `ondatastream` for user feedback during transfers.
|