Skip to content

Fix CFBundleURLTypes merging. #2961

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 11, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 33 additions & 43 deletions lib/services/ios-project-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import * as constants from "../constants";
import * as helpers from "../common/helpers";
import { attachAwaitDetach } from "../common/helpers";
import * as projectServiceBaseLib from "./platform-project-service-base";
import { PlistSession } from "plist-merge-patch";
import { PlistSession, Reporter } from "plist-merge-patch";
import { EOL } from "os";
import * as temp from "temp";
import * as plist from "plist";
Expand Down Expand Up @@ -723,7 +723,13 @@ We will now place an empty obsolete compatability white screen LauncScreen.xib f
return;
}

let session = new PlistSession({ log: (txt: string) => this.$logger.trace("Info.plist: " + txt) });
const reporterTraceMessage = "Info.plist:";
const reporter: Reporter = {
log: (txt: string) => this.$logger.trace(`${reporterTraceMessage} ${txt}`),
warn: (txt: string) => this.$logger.warn(`${reporterTraceMessage} ${txt}`)
};

let session = new PlistSession(reporter);
let makePatch = (plistPath: string) => {
if (!this.$fs.exists(plistPath)) {
this.$logger.trace("No plist found at: " + plistPath);
Expand All @@ -743,17 +749,7 @@ We will now place an empty obsolete compatability white screen LauncScreen.xib f
makePatch(pluginInfoPlistPath);
}

if (!buildOptions.release && projectData.projectId) {
const modifiedPlistContent = this.updateCFBundleURLSchemes(infoPlistPath, projectData);

session.patch({
name: "CFBundleURLTypes from Info.plist and required one for restarting application",
read: () => modifiedPlistContent
});

} else {
makePatch(infoPlistPath);
}
makePatch(infoPlistPath);

if (projectData.projectId) {
session.patch({
Expand All @@ -770,42 +766,36 @@ We will now place an empty obsolete compatability white screen LauncScreen.xib f
});
}

if (!buildOptions.release && projectData.projectId) {
session.patch({
name: "CFBundleURLTypes from package.json nativescript.id",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this name looks really strange

read: () =>
`<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleURLSchemes</key>
<array>
<string>${projectData.projectId.replace(/[^A-Za-z0-9]/g, "")}</string>
</array>
</dict>
</array>
</dict>
</plist>`
});
}

let plistContent = session.build();

this.$logger.trace("Info.plist: Write to: " + this.getPlatformData(projectData).configurationFilePath);
this.$fs.writeFile(this.getPlatformData(projectData).configurationFilePath, plistContent);
}

private updateCFBundleURLSchemes(infoPlistPath: string, projectData: IProjectData): string {
// This code is required due to bug in session.patch logic which cannot merge values which are both arrays - it uses the second one directly.
// In our case we want to merge the values of CFBundleURLSchemes (which are arrays), which are in CFBundleURLTypes arrays.
let parsedPlist: any = plist.parse(this.$fs.readFile(infoPlistPath).toString());
parsedPlist.CFBundleURLTypes = parsedPlist.CFBundleURLTypes || [];

const appIdCfBundleUrlScheme = projectData.projectId.replace(/[^A-Za-z0-9]/g, "");

let hasAddedCFBundleURLSchemes = false;

_.each(parsedPlist.CFBundleURLTypes, type => {
if (type.CFBundleURLSchemes) {
hasAddedCFBundleURLSchemes = true;
type.CFBundleURLSchemes.push(appIdCfBundleUrlScheme);
return false;
}
});

if (!hasAddedCFBundleURLSchemes) {
parsedPlist.CFBundleURLTypes.push(
{
CFBundleURLSchemes: [appIdCfBundleUrlScheme]
}
);
}

const newPlistContent = plist.build(parsedPlist);
return newPlistContent;
}

private getAllInstalledPlugins(projectData: IProjectData): Promise<IPluginData[]> {
return (<IPluginsService>this.$injector.resolve("pluginsService")).getAllInstalledPlugins(projectData);
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"osenv": "0.1.3",
"pbxproj-dom": "1.0.11",
"plist": "1.1.0",
"plist-merge-patch": "0.0.9",
"plist-merge-patch": "0.1.0",
"plistlib": "0.2.1",
"progress-stream": "1.1.1",
"properties-parser": "0.2.3",
Expand Down