Skip to content

Commit f24c102

Browse files
Fix parsing of simulator plist files
Some watchkit apps have xml plist file and when we try to read them as binary plists, the bplist module fails. Catch this error and try to parse them with plist module.
1 parent 0f9709f commit f24c102

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

lib/iphone-simulator-common.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import * as path from "path";
88
import * as os from "os";
99
import xcode = require("./xcode");
1010
let bplistParser = require("bplist-parser");
11+
let plist = require("plist");
1112
let osenv = require("osenv");
1213
let isDeviceLogOperationStarted = false;
1314
let pid: string;
@@ -26,10 +27,9 @@ export function getInstalledApplications(deviceId: string): IFuture<IApplication
2627
let applicationDirContents = fs.readdirSync(fullApplicationPath);
2728
let applicationName = _.find(applicationDirContents, fileName => path.extname(fileName) === ".app");
2829
let plistFilePath = path.join(fullApplicationPath, applicationName, "Info.plist");
29-
let applicationData = parseFile(plistFilePath).wait();
3030
result.push({
3131
guid: applicationGuid,
32-
appIdentifier: applicationData[0].CFBundleIdentifier,
32+
appIdentifier: getBundleIdentifier(plistFilePath).wait(),
3333
path: path.join(fullApplicationPath, applicationName)
3434
});
3535
}
@@ -96,4 +96,18 @@ function parseFile(plistFilePath: string): IFuture<any> {
9696
}
9797
});
9898
return future;
99+
}
100+
101+
function getBundleIdentifier(plistFilePath: string): IFuture<string> {
102+
return (() => {
103+
let plistData: any;
104+
try {
105+
plistData = parseFile(plistFilePath).wait()[0];
106+
} catch (err) {
107+
let content = fs.readFileSync(plistFilePath).toString();
108+
plistData = plist.parse(content);
109+
}
110+
111+
return plistData && plistData.CFBundleIdentifier;
112+
}).future<string>()();
99113
}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"lodash": "3.2.0",
3333
"nodobjc": "https://github.com/telerik/NodObjC/tarball/v2.0.0.1",
3434
"osenv": "0.1.3",
35+
"plist": "1.1.0",
3536
"yargs": "3.15.0"
3637
},
3738
"devDependencies": {

0 commit comments

Comments
 (0)