Skip to content

Commit 7e51ba8

Browse files
authored
Fix CFBundleURLTypes merging. (#2961)
1 parent 19e6829 commit 7e51ba8

File tree

2 files changed

+34
-44
lines changed

2 files changed

+34
-44
lines changed

lib/services/ios-project-service.ts

+33-43
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import * as constants from "../constants";
66
import * as helpers from "../common/helpers";
77
import { attachAwaitDetach } from "../common/helpers";
88
import * as projectServiceBaseLib from "./platform-project-service-base";
9-
import { PlistSession } from "plist-merge-patch";
9+
import { PlistSession, Reporter } from "plist-merge-patch";
1010
import { EOL } from "os";
1111
import * as temp from "temp";
1212
import * as plist from "plist";
@@ -723,7 +723,13 @@ We will now place an empty obsolete compatability white screen LauncScreen.xib f
723723
return;
724724
}
725725

726-
let session = new PlistSession({ log: (txt: string) => this.$logger.trace("Info.plist: " + txt) });
726+
const reporterTraceMessage = "Info.plist:";
727+
const reporter: Reporter = {
728+
log: (txt: string) => this.$logger.trace(`${reporterTraceMessage} ${txt}`),
729+
warn: (txt: string) => this.$logger.warn(`${reporterTraceMessage} ${txt}`)
730+
};
731+
732+
let session = new PlistSession(reporter);
727733
let makePatch = (plistPath: string) => {
728734
if (!this.$fs.exists(plistPath)) {
729735
this.$logger.trace("No plist found at: " + plistPath);
@@ -743,17 +749,7 @@ We will now place an empty obsolete compatability white screen LauncScreen.xib f
743749
makePatch(pluginInfoPlistPath);
744750
}
745751

746-
if (!buildOptions.release && projectData.projectId) {
747-
const modifiedPlistContent = this.updateCFBundleURLSchemes(infoPlistPath, projectData);
748-
749-
session.patch({
750-
name: "CFBundleURLTypes from Info.plist and required one for restarting application",
751-
read: () => modifiedPlistContent
752-
});
753-
754-
} else {
755-
makePatch(infoPlistPath);
756-
}
752+
makePatch(infoPlistPath);
757753

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

769+
if (!buildOptions.release && projectData.projectId) {
770+
session.patch({
771+
name: "CFBundleURLTypes from package.json nativescript.id",
772+
read: () =>
773+
`<?xml version="1.0" encoding="UTF-8"?>
774+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
775+
<plist version="1.0">
776+
<dict>
777+
<key>CFBundleURLTypes</key>
778+
<array>
779+
<dict>
780+
<key>CFBundleTypeRole</key>
781+
<string>Editor</string>
782+
<key>CFBundleURLSchemes</key>
783+
<array>
784+
<string>${projectData.projectId.replace(/[^A-Za-z0-9]/g, "")}</string>
785+
</array>
786+
</dict>
787+
</array>
788+
</dict>
789+
</plist>`
790+
});
791+
}
792+
773793
let plistContent = session.build();
774794

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

779-
private updateCFBundleURLSchemes(infoPlistPath: string, projectData: IProjectData): string {
780-
// 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.
781-
// In our case we want to merge the values of CFBundleURLSchemes (which are arrays), which are in CFBundleURLTypes arrays.
782-
let parsedPlist: any = plist.parse(this.$fs.readFile(infoPlistPath).toString());
783-
parsedPlist.CFBundleURLTypes = parsedPlist.CFBundleURLTypes || [];
784-
785-
const appIdCfBundleUrlScheme = projectData.projectId.replace(/[^A-Za-z0-9]/g, "");
786-
787-
let hasAddedCFBundleURLSchemes = false;
788-
789-
_.each(parsedPlist.CFBundleURLTypes, type => {
790-
if (type.CFBundleURLSchemes) {
791-
hasAddedCFBundleURLSchemes = true;
792-
type.CFBundleURLSchemes.push(appIdCfBundleUrlScheme);
793-
return false;
794-
}
795-
});
796-
797-
if (!hasAddedCFBundleURLSchemes) {
798-
parsedPlist.CFBundleURLTypes.push(
799-
{
800-
CFBundleURLSchemes: [appIdCfBundleUrlScheme]
801-
}
802-
);
803-
}
804-
805-
const newPlistContent = plist.build(parsedPlist);
806-
return newPlistContent;
807-
}
808-
809799
private getAllInstalledPlugins(projectData: IProjectData): Promise<IPluginData[]> {
810800
return (<IPluginsService>this.$injector.resolve("pluginsService")).getAllInstalledPlugins(projectData);
811801
}

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
"osenv": "0.1.3",
6060
"pbxproj-dom": "1.0.11",
6161
"plist": "1.1.0",
62-
"plist-merge-patch": "0.0.9",
62+
"plist-merge-patch": "0.1.0",
6363
"plistlib": "0.2.1",
6464
"progress-stream": "1.1.1",
6565
"properties-parser": "0.2.3",

0 commit comments

Comments
 (0)