Skip to content

Commit d61bc71

Browse files
Fatme HavaluovaFatme Havaluova
authored andcommitted
Support device option for Xcode 5 or older
1 parent e80db60 commit d61bc71

File tree

3 files changed

+25
-16
lines changed

3 files changed

+25
-16
lines changed

lib/iphone-simulator-xcode-5.ts

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,38 @@
22
"use strict";
33

44
import options = require("./options");
5+
import utils = require("./utils");
56
import util = require("util");
67

8+
var $ = require("NodObjC");
79

810
export class XCode5Simulator implements ISimulator {
911

10-
private static DEFAULT_DEVICE_IDENTIFIER = "Resizable-iPad";
12+
private static DEFAULT_DEVICE_IDENTIFIER = "iPhone";
1113

12-
private static allowedDeviceIdentifiers = [
13-
"iPhone",
14-
"iPhone Retina (3.5-inch)",
15-
"iPhone Retina (4-inch)",
16-
"iPhone Retina (4-inch 64-bit)",
17-
"iPad",
18-
"iPad Retina",
19-
"iPad Retina (64-bit)"
20-
];
14+
private static allowedDeviceIdentifiers: IDictionary<string> = {
15+
"iPhone": "iPhone",
16+
"iPhone-Retina-3.5-inch": "iPhone Retina (3.5-inch)",
17+
"iPhone-Retina-4-inch": "iPhone Retina (4-inch)",
18+
"iPhone-Retina-4-inch-64-bit": "iPhone Retina (4-inch 64-bit)",
19+
"iPad": "iPad",
20+
"iPad-Retina": "iPad Retina",
21+
"iPad-Retina-64-bit": "iPad Retina (64-bit)"
22+
}
2123

2224
public validateDeviceIdentifier(): void {
25+
var identifiers: string[] = _.keys(XCode5Simulator.allowedDeviceIdentifiers);
26+
if(!_.contains(identifiers, options.device)) {
27+
throw new Error(util.format("Invalid device identifier %s. Valid device identifiers are %s.", options.device, utils.stringify(identifiers)));
28+
}
2329
}
2430

2531
public setSimulatedDevice(config:any): void {
26-
config("setSimulatedDeviceInfoName", this.deviceIdentifier);
32+
config("setSimulatedDeviceInfoName", $(this.deviceIdentifier));
2733
}
2834

29-
private get deviceIdentifier() {
30-
return options.devie || XCode5Simulator.DEFAULT_DEVICE_IDENTIFIER;
35+
private get deviceIdentifier(): string {
36+
var identifier = options.device || XCode5Simulator.DEFAULT_DEVICE_IDENTIFIER;
37+
return XCode5Simulator.allowedDeviceIdentifiers[identifier];
3138
}
3239
}

lib/iphone-simulator-xcode-6.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ export class XCode6Simulator implements ISimulator {
3030
}
3131

3232
public validateDeviceIdentifier(): void {
33-
if(!_.contains(XCode6Simulator.allowedDeviceIdentifiers, this.deviceIdentifier)) {
34-
throw new Error(util.format("Invalid device identifier %s. Valid device identifiers are %s.", this.deviceIdentifier, utils.stringify(XCode6Simulator.allowedDeviceIdentifiers)));
33+
if(!_.contains(XCode6Simulator.allowedDeviceIdentifiers, options.device)) {
34+
throw new Error(util.format("Invalid device identifier %s. Valid device identifiers are %s.", options.device, utils.stringify(XCode6Simulator.allowedDeviceIdentifiers)));
3535
}
3636
}
3737

lib/iphone-simulator.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,9 @@ export class iPhoneSimulator implements IiPhoneSimulator {
7777
simulator = new xcode5SimulatorLib.XCode5Simulator();
7878
}
7979

80-
simulator.validateDeviceIdentifier();
80+
if(options.device) {
81+
simulator.validateDeviceIdentifier();
82+
}
8183
simulator.setSimulatedDevice(config);
8284

8385
config("setLocalizedClientName", $("ios-sim-portable"));

0 commit comments

Comments
 (0)