diff --git a/lib/common b/lib/common index c01fd47f28..f906af7e73 160000 --- a/lib/common +++ b/lib/common @@ -1 +1 @@ -Subproject commit c01fd47f2815ed528747427bcf72a4e6dc66da18 +Subproject commit f906af7e73171ca839a8313f4d33f8e6a0ae88ee diff --git a/lib/services/ios-project-service.ts b/lib/services/ios-project-service.ts index 2a0b1629be..deec5de691 100644 --- a/lib/services/ios-project-service.ts +++ b/lib/services/ios-project-service.ts @@ -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: () => - ` - - - - CFBundleIdentifier - ${projectData.projectId} - - ` + 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: () => ` - CFBundleURLTypes - - - CFBundleURLSchemes - - ${projectData.projectId.replace(/[^A-Za-z0-9]/g, "")} - - - + CFBundleIdentifier + ${projectData.projectId} ` }); @@ -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 { return (this.$injector.resolve("pluginsService")).getAllInstalledPlugins(projectData); }