Skip to content

Commit a8763db

Browse files
Fix merging of CFBundleURLSchemes in debug builds (#2913)
In debug builds we add CFBundleURLSchemes that's required to restart the app on Windows. However, in case the Info.plist of the application already has the same key, the module we are using is not merging the values correctly. Fix this by manually merging the values.
1 parent 6df2bc1 commit a8763db

File tree

2 files changed

+42
-24
lines changed

2 files changed

+42
-24
lines changed

lib/common

lib/services/ios-project-service.ts

+41-23
Original file line numberDiff line numberDiff line change
@@ -743,40 +743,28 @@ We will now place an empty obsolete compatability white screen LauncScreen.xib f
743743
makePatch(pluginInfoPlistPath);
744744
}
745745

746-
makePatch(infoPlistPath);
746+
if (!buildOptions.release && projectData.projectId) {
747+
const modifiedPlistContent = this.updateCFBundleURLSchemes(infoPlistPath, projectData);
747748

748-
if (projectData.projectId) {
749749
session.patch({
750-
name: "CFBundleIdentifier from package.json nativescript.id",
751-
read: () =>
752-
`<?xml version="1.0" encoding="UTF-8"?>
753-
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
754-
<plist version="1.0">
755-
<dict>
756-
<key>CFBundleIdentifier</key>
757-
<string>${projectData.projectId}</string>
758-
</dict>
759-
</plist>`
750+
name: "CFBundleURLTypes from Info.plist and required one for restarting application",
751+
read: () => modifiedPlistContent
760752
});
753+
754+
} else {
755+
makePatch(infoPlistPath);
761756
}
762757

763-
if (!buildOptions.release && projectData.projectId) {
758+
if (projectData.projectId) {
764759
session.patch({
765-
name: "CFBundleURLTypes from package.json nativescript.id",
760+
name: "CFBundleIdentifier from package.json nativescript.id",
766761
read: () =>
767762
`<?xml version="1.0" encoding="UTF-8"?>
768763
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
769764
<plist version="1.0">
770765
<dict>
771-
<key>CFBundleURLTypes</key>
772-
<array>
773-
<dict>
774-
<key>CFBundleURLSchemes</key>
775-
<array>
776-
<string>${projectData.projectId.replace(/[^A-Za-z0-9]/g, "")}</string>
777-
</array>
778-
</dict>
779-
</array>
766+
<key>CFBundleIdentifier</key>
767+
<string>${projectData.projectId}</string>
780768
</dict>
781769
</plist>`
782770
});
@@ -788,6 +776,36 @@ We will now place an empty obsolete compatability white screen LauncScreen.xib f
788776
this.$fs.writeFile(this.getPlatformData(projectData).configurationFilePath, plistContent);
789777
}
790778

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

0 commit comments

Comments
 (0)