Skip to content
This repository was archived by the owner on Feb 2, 2021. It is now read-only.

Commit eec8ca8

Browse files
Merge pull request #581 from telerik/vladimirov/fix-ios-device-discovery
Fix deploy on iOS devices
2 parents 315e6f9 + d769f8f commit eec8ca8

File tree

4 files changed

+57
-21
lines changed

4 files changed

+57
-21
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ Contains common infrastructure for CLIs - mainly AppBuilder and NativeScript.
77
Installation
88
===
99

10-
Latest version: 0.4.0
10+
Latest version: 0.4.1
1111

12-
Release date: 2015, December 29
12+
Release date: 2016, January 08
1313

1414
### System Requirements
1515

mobile/ios/ios-proxy-services.ts

+36-9
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import * as path from "path";
55
import * as iOSCore from "./ios-core";
66
import * as helpers from "../../helpers";
77
import * as plistlib from "plistlib";
8+
import Future = require("fibers/future");
89

910
export class MobileServices {
1011
public static APPLE_FILE_CONNECTION: string = "com.apple.afc";
@@ -161,6 +162,7 @@ export class AfcClient implements Mobile.IAfcClient {
161162

162163
public transfer(localFilePath: string, devicePath: string): IFuture<void> {
163164
return(() => {
165+
let future = new Future<void>();
164166
this.ensureDevicePathExist(path.dirname(devicePath));
165167
let reader = this.$fs.createReadStream(localFilePath);
166168
devicePath = helpers.fromWindowsRelativePathToUnix(devicePath);
@@ -169,19 +171,44 @@ export class AfcClient implements Mobile.IAfcClient {
169171

170172
let target = this.open(devicePath, "w");
171173
let localFilePathSize = this.$fs.getFileSize(localFilePath).wait();
174+
let isErrorCode21Raised = false,
175+
futureThrow = (err: Error) => {
176+
if (!future.isResolved()) {
177+
future.throw(err);
178+
}
179+
};
172180

173181
reader.on("data", (data: NodeBuffer) => {
174-
target.write(data, data.length);
175-
this.$logger.trace("transfer-> localFilePath: '%s', devicePath: '%s', localFilePathSize: '%s', transferred bytes: '%s'",
176-
localFilePath, devicePath, localFilePathSize.toString(), data.length.toString());
177-
})
178-
.on("error", (error: Error) => {
179-
this.$errors.fail(error);
180-
})
181-
.on("end", () => target.close());
182+
try {
183+
target.write(data, data.length);
184+
this.$logger.trace("transfer-> localFilePath: '%s', devicePath: '%s', localFilePathSize: '%s', transferred bytes: '%s'",
185+
localFilePath, devicePath, localFilePathSize.toString(), data.length.toString());
186+
} catch(err) {
187+
if(err.message.indexOf("Result is: '21'") !== -1 && !isErrorCode21Raised) {
188+
// Error code 21 is kAFCInterruptedError. It looks like in most cases it is raised on the first package that we try to transfer.
189+
// However ignoring this error on the first package, does not prevent the application from installing and working correctly.
190+
// So ignore the first occurrence of the error only.
191+
this.$logger.warn(err.message);
192+
isErrorCode21Raised = true;
193+
} else {
194+
futureThrow(err);
195+
}
196+
}
197+
});
198+
199+
reader.on("error", (error: Error) => {
200+
futureThrow(error);
201+
});
182202

183-
this.$fs.futureFromEvent(reader, "close").wait();
203+
reader.on("end", () => target.close());
204+
205+
reader.on("close", () => {
206+
if(!future.isResolved()) {
207+
future.return();
208+
}
209+
});
184210

211+
future.wait();
185212
}).future<void>()();
186213
}
187214

mobile/mobile-core/devices-service.ts

+9-3
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,10 @@ export class DevicesService implements Mobile.IDevicesService {
103103
setInterval(() => {
104104
fiberBootstrap.run(() => {
105105
try {
106-
Future.wait([this.$iOSDeviceDiscovery.checkForDevices(),
107-
this.$androidDeviceDiscovery.checkForDevices()]);
106+
// This code could be faster, by using Future.wait([...]), but it turned out this is breaking iOS deployment on Mac
107+
// It's causing error 21 when deploying on some iOS devices during transfer of the first package.
108+
this.$iOSDeviceDiscovery.checkForDevices().wait();
109+
this.$androidDeviceDiscovery.checkForDevices().wait();
108110
} catch (err) {
109111
this.$logger.trace("Error while checking for new devices.", err);
110112
}
@@ -267,7 +269,11 @@ export class DevicesService implements Mobile.IDevicesService {
267269
let device = this._devices[deviceIdentifier];
268270
device.deploy(packageFile, packageName).wait();
269271
if(device.applicationManager.canStartApplication()) {
270-
device.applicationManager.startApplication(packageName).wait();
272+
try {
273+
device.applicationManager.startApplication(packageName).wait();
274+
} catch(err) {
275+
this.$logger.trace("Unable to start application on device. Error is: ", err);
276+
}
271277
}
272278
} else {
273279
throw new Error(`Cannot find device with identifier ${deviceIdentifier}.`);

services/messages-service.ts

+10-7
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import * as util from "util";
55
import * as path from "path";
6+
import * as fiberBootstrap from "../fiber-bootstrap";
67

78
export class MessagesService implements IMessagesService {
89
private _pathsToMessageJsonFiles: string[] = null;
@@ -70,13 +71,15 @@ export class MessagesService implements IMessagesService {
7071
}
7172

7273
private refreshMessageJsonContentsCache(): void {
73-
this._messageJsonFilesContentsCache = [];
74-
_.each(this.pathsToMessageJsonFiles, path => {
75-
if (!this.$fs.exists(path).wait()) {
76-
throw new Error("Message json file " + path + " does not exist.");
77-
}
78-
79-
this._messageJsonFilesContentsCache.push(this.$fs.readJson(path).wait());
74+
fiberBootstrap.run(() => {
75+
this._messageJsonFilesContentsCache = [];
76+
_.each(this.pathsToMessageJsonFiles, path => {
77+
if (!this.$fs.exists(path).wait()) {
78+
throw new Error("Message json file " + path + " does not exist.");
79+
}
80+
81+
this._messageJsonFilesContentsCache.push(this.$fs.readJson(path).wait());
82+
});
8083
});
8184
}
8285

0 commit comments

Comments
 (0)