@@ -6,7 +6,7 @@ import * as constants from "../constants";
6
6
import * as helpers from "../common/helpers" ;
7
7
import { attachAwaitDetach } from "../common/helpers" ;
8
8
import * as projectServiceBaseLib from "./platform-project-service-base" ;
9
- import { PlistSession } from "plist-merge-patch" ;
9
+ import { PlistSession , Reporter } from "plist-merge-patch" ;
10
10
import { EOL } from "os" ;
11
11
import * as temp from "temp" ;
12
12
import * as plist from "plist" ;
@@ -723,7 +723,13 @@ We will now place an empty obsolete compatability white screen LauncScreen.xib f
723
723
return ;
724
724
}
725
725
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 ) ;
727
733
let makePatch = ( plistPath : string ) => {
728
734
if ( ! this . $fs . exists ( plistPath ) ) {
729
735
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
743
749
makePatch ( pluginInfoPlistPath ) ;
744
750
}
745
751
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 ) ;
757
753
758
754
if ( projectData . projectId ) {
759
755
session . patch ( {
@@ -770,42 +766,36 @@ We will now place an empty obsolete compatability white screen LauncScreen.xib f
770
766
} ) ;
771
767
}
772
768
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
+
773
793
let plistContent = session . build ( ) ;
774
794
775
795
this . $logger . trace ( "Info.plist: Write to: " + this . getPlatformData ( projectData ) . configurationFilePath ) ;
776
796
this . $fs . writeFile ( this . getPlatformData ( projectData ) . configurationFilePath , plistContent ) ;
777
797
}
778
798
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
-
809
799
private getAllInstalledPlugins ( projectData : IProjectData ) : Promise < IPluginData [ ] > {
810
800
return ( < IPluginsService > this . $injector . resolve ( "pluginsService" ) ) . getAllInstalledPlugins ( projectData ) ;
811
801
}
0 commit comments