Skip to content

Commit e39f13e

Browse files
committed
Fix CFBundleURLTypes merging.
1 parent 0166da3 commit e39f13e

File tree

2 files changed

+33
-44
lines changed

2 files changed

+33
-44
lines changed

lib/services/ios-project-service.ts

+32-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,12 @@ 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 reporter: Reporter = {
727+
log: (txt: string) => this.$logger.trace("Info.plist: " + txt),
728+
warn: (txt: string) => this.$logger.warn("Info.plist: " + txt),
729+
}
730+
731+
let session = new PlistSession(reporter);
727732
let makePatch = (plistPath: string) => {
728733
if (!this.$fs.exists(plistPath)) {
729734
this.$logger.trace("No plist found at: " + plistPath);
@@ -743,17 +748,7 @@ We will now place an empty obsolete compatability white screen LauncScreen.xib f
743748
makePatch(pluginInfoPlistPath);
744749
}
745750

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-
}
751+
makePatch(infoPlistPath);
757752

758753
if (projectData.projectId) {
759754
session.patch({
@@ -770,42 +765,36 @@ We will now place an empty obsolete compatability white screen LauncScreen.xib f
770765
});
771766
}
772767

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

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

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-
809798
private getAllInstalledPlugins(projectData: IProjectData): Promise<IPluginData[]> {
810799
return (<IPluginsService>this.$injector.resolve("pluginsService")).getAllInstalledPlugins(projectData);
811800
}

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)