@@ -6,7 +6,7 @@ import * as constants from "../constants";
66import * as helpers from "../common/helpers" ;
77import { attachAwaitDetach } from "../common/helpers" ;
88import * as projectServiceBaseLib from "./platform-project-service-base" ;
9- import { PlistSession } from "plist-merge-patch" ;
9+ import { PlistSession , Reporter } from "plist-merge-patch" ;
1010import { EOL } from "os" ;
1111import * as temp from "temp" ;
1212import * 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 - Z a - z 0 - 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 - Z a - z 0 - 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 }
0 commit comments