Skip to content

Commit c150c57

Browse files
author
Dimitar Kerezov
committed
Improve docs
1 parent 382c9c6 commit c150c57

File tree

1 file changed

+286
-2
lines changed

1 file changed

+286
-2
lines changed

README.md

Lines changed: 286 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ ios-device-lib
33

44
JavaScript library, designed to facilitate communication with iOS devices. The library’s interface is Promise-based.
55

6-
Usage
6+
Quick overview
77
==
88

99
In order to use `ios-device-lib`, just add a reference to it in your package.json:
@@ -33,7 +33,291 @@ dl.install("./app.ipa", ["deviceId1", "deviceId2"])
3333
});
3434
```
3535

36+
Building
37+
==
38+
The `ios-device-lib` package can be built on either Windows (requires Visual Studio) or macOS (requires Xcode). In order to build the application one should simply open the `.sln` or `.xcodeproj` file with the respective tool and click build. Whenever building in **release** configuration, the result binary will end up in `bin/<platform-name>/<architecture>`, relative to the root of this repository. For example `bin/win32/x64/` or `bin/darwin/x64/`. The JavaScript counterpart of the C++ code expects the binaries to be present in those exact locations, so one would have to build at least once prior to using the application.
39+
40+
Inter-process Communication
41+
==
42+
This application consists of two separate layers - one `C++` and one `Node.js`. The `C++` layer implements the application's business logic, whereas the `Node.js` layer exists simply for alleviation. Whenever the `Node.js` part is used, it launches the `C++` binary and initiates communication with it. This communication consists of requests **to the binary** via the `stdin` pipe and responses **from the binary** via the `stdout` pipe. Currently the `stderr` pipe is only used for debugging purposes.
43+
44+
The nature of this way of communication imposes some quirks:
45+
* All request messages are marked with an unique identifier which is also present in the response messages. This way the `Node.js` layer can distinguish between different messages and match a request with it's response counterpart
46+
* All messages are printed in binary on the `stdout` (and the `stderr`) pipe. Each message is prefixed with a 4 byte header, containing the length of the succeeding message. These 4-byte prefixes appear as peculiar symbols in the console whenever one decides to launch the binary directly. This is necessary as the messages have variable length and in addition it alleviates printing from the `C++` code as the strings we want to print might contain `NULL` characters which would otherwise terminate printing.
47+
3648
API Reference
3749
==
38-
This section contains information about each public method.
50+
In order to use the application directly one can either launch the binary, either directly or from within an IDE, or use the JavaScript API. Whenever using this library **make sure that there is at least one actual iOS device attached to the system**. This library has no functionality whatsoever without actual devices.
51+
52+
## C++ Binary
53+
Upon launching the binary it will report all devices currently attached in the following form:
54+
```
55+
{
56+
"deviceColor": "1",
57+
"deviceId": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
58+
"deviceName": "iPhone",
59+
"event": "deviceFound",
60+
"productType": "iPhone9,4",
61+
"productVersion": "11.0.3",
62+
"status": "Connected"
63+
}
64+
```
65+
66+
After that the binary is ready to accept requests via its standart input. Currently each passed message **must be on one line**, ending with a new line (Enter key) in order for it to be parsed correctly. Each message contains the **name** of the method, which you'd like to invoke, an **identification string** and the **method's arguments**. Messages are processed asynchronously, hence multiple messages can be passed at once. Example messages for the different opperations can be found below:
67+
68+
### List applications
69+
{
70+
"methods": [
71+
{
72+
"id": "1",
73+
"name": "apps",
74+
"args": [
75+
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
76+
"yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy"
77+
]
78+
}
79+
]
80+
}
81+
82+
### Install application
83+
{
84+
"methods": [
85+
{
86+
"id": "2",
87+
"name": "install",
88+
"args": [
89+
"C:\\\apps\\\app.ipa",
90+
[
91+
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
92+
"yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy"
93+
]
94+
]
95+
}
96+
]
97+
}
98+
99+
### Uninstall application
100+
{
101+
"methods": [
102+
{
103+
"id": "3",
104+
"name": "uninstall",
105+
"args": [
106+
"com.sample.MyApp",
107+
[
108+
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
109+
"yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy"
110+
]
111+
]
112+
}
113+
]
114+
}
115+
116+
### List files in an application
117+
{
118+
"methods": [
119+
{
120+
"id": "4",
121+
"name": "list",
122+
"args": [
123+
{
124+
"appId": "com.sample.MyApp",
125+
"deviceId": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
126+
"path": "Library\\\Application Support
127+
}
128+
]
129+
}
130+
]
131+
}
132+
133+
### Upload a file from the local file system to the device
134+
{
135+
"methods": [
136+
{
137+
"id": "5",
138+
"name": "upload",
139+
"args": [
140+
{
141+
"appId": "com.sample.MyApp",
142+
"deviceId": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
143+
"source": "D:\\\Project\\\app.js",
144+
"destination": "Library\\\Application Support\\\LiveSync\\\app\\\app.js"
145+
}
146+
]
147+
}
148+
]
149+
}
150+
151+
### Delete a file from the device
152+
{
153+
"methods": [
154+
{
155+
"id": "6",
156+
"name": "delete",
157+
"args": [
158+
{
159+
"appId": "com.sample.MyApp",
160+
"deviceId": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
161+
"destination": "Library\\\Application Support\\\LiveSync\\\app\\\app.js"
162+
}
163+
]
164+
}
165+
]
166+
}
167+
168+
### Retrieve the contents of a file from the device
169+
{
170+
"methods": [
171+
{
172+
"id": "7",
173+
"name": "read",
174+
"args": [
175+
{
176+
"appId": "com.sample.MyApp",
177+
"deviceId": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
178+
"path": "Library\\\Application Support\\\LiveSync\\\app\\\app.js"
179+
}
180+
]
181+
}
182+
]
183+
}
184+
185+
### Download a file from the device to the local system
186+
{
187+
"methods": [
188+
{
189+
"id": "8",
190+
"name": "download",
191+
"args": [
192+
{
193+
"appId": "com.sample.MyApp",
194+
"deviceId": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
195+
"source": "Library\\\Application Support\\\LiveSync\\\app\\\app.js",
196+
"destination": "D:\\\Downloads\\\app.js"
197+
}
198+
]
199+
}
200+
]
201+
}
202+
203+
### Start printing the device log for a device
204+
{
205+
"methods": [
206+
{
207+
"id": "9",
208+
"name": "log",
209+
"args": [
210+
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
211+
]
212+
}
213+
]
214+
}
215+
216+
### Post a notification to a device. (As if ot was dispatched via NSNotificationCenter). This call is non-blocking.
217+
#### Post
218+
{
219+
"methods": [
220+
{
221+
"id": "10",
222+
"name": "postNotification",
223+
"args": [
224+
{
225+
"deviceId": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
226+
"commandType": "PostNotification",
227+
"notificationName": "com.sample.MyApp:NativeScript.Debug.AttachAvailabilityQuery"
228+
}
229+
]
230+
}
231+
]
232+
}
233+
234+
#### Observe
235+
{
236+
"methods": [
237+
{
238+
"id": "11",
239+
"name": "postNotification",
240+
"args": [
241+
{
242+
"deviceId": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
243+
"commandType": "ObserveNotification",
244+
"notificationName": "com.sample.MyApp:NativeScript.Debug.AttachAvailable"
245+
}
246+
]
247+
}
248+
]
249+
}
250+
251+
### Post a notification to a device and await its response. This call is blocking.
252+
{
253+
"methods": [
254+
{
255+
"id": "12",
256+
"name": "awaitNotificationResponse",
257+
"args": [
258+
{
259+
"deviceId": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
260+
"socket": 10,
261+
"timeout": 9,
262+
"responseCommandType": "RelayNotification",
263+
"responsePropertyName": "Name"
264+
}
265+
]
266+
}
267+
]
268+
}
269+
270+
### Start an application.
271+
{
272+
"methods": [
273+
{
274+
"id": "13",
275+
"name": "start",
276+
"args": [
277+
{
278+
"appId": "com.sample.MyApp",
279+
"deviceId": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
280+
}
281+
]
282+
}
283+
]
284+
}
285+
286+
### Stop a running application.
287+
{
288+
"methods": [
289+
{
290+
"id": "14",
291+
"name": "stop",
292+
"args": [
293+
{
294+
"appId": "com.sample.MyApp",
295+
"deviceId": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
296+
}
297+
]
298+
}
299+
]
300+
}
301+
302+
## JavaScript interface
303+
A detailed definition of all the methods can be found [here](https://github.com/telerik/ios-device-lib/blob/master/typings/interfaces.d.ts#L127)
304+
305+
Additional information
306+
==
307+
* Upon launching the `ios-device-lib` binary it will immediately start a detached thread with a run loop so that it can proactively detect attaching and detaching of devices.
308+
* All requests to the binary are executed in separate threads
309+
* **Error understanding:** Whenever an error is raised, for example:
310+
```
311+
{
312+
"deviceId": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
313+
"error": {
314+
"code": -402653081,
315+
"deviceId": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
316+
"message": "Could not install application"
317+
},
318+
"id": "1"
319+
}
320+
```
321+
How does one go about deciphering the error code?
39322

323+
First off you'd need to convert the code to hex (this can easily be done with a calculator application for example). So `-402653081` becomes `FFFFFFFFE8000067` or `E8000067` if we disregard the sign. Using this hex code you can look the error up in [this](https://github.com/samdmarshall/SDMMobileDevice/blob/master/Framework/include/SDMMobileDevice/SDMMD_Error.h) header file. In this example we can see that this is a `kAMDAPIInternalError`, hence an internal error.

0 commit comments

Comments
 (0)