Skip to content

Fix merging of CFBundleURLSchemes in debug builds #2913

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
Jun 23, 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
2 changes: 1 addition & 1 deletion lib/common
Submodule common updated 1 files
+2 −1 definitions/plist.d.ts
64 changes: 41 additions & 23 deletions lib/services/ios-project-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -743,40 +743,28 @@ We will now place an empty obsolete compatability white screen LauncScreen.xib f
makePatch(pluginInfoPlistPath);
}

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

if (projectData.projectId) {
session.patch({
name: "CFBundleIdentifier from package.json nativescript.id",
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>CFBundleIdentifier</key>
<string>${projectData.projectId}</string>
</dict>
</plist>`
name: "CFBundleURLTypes from Info.plist and required one for restarting application",
read: () => modifiedPlistContent
});

} else {
makePatch(infoPlistPath);
}

if (!buildOptions.release && projectData.projectId) {
if (projectData.projectId) {
session.patch({
name: "CFBundleURLTypes from package.json nativescript.id",
name: "CFBundleIdentifier from package.json nativescript.id",
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>CFBundleURLSchemes</key>
<array>
<string>${projectData.projectId.replace(/[^A-Za-z0-9]/g, "")}</string>
</array>
</dict>
</array>
<key>CFBundleIdentifier</key>
<string>${projectData.projectId}</string>
</dict>
</plist>`
});
Expand All @@ -788,6 +776,36 @@ We will now place an empty obsolete compatability white screen LauncScreen.xib f
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