@@ -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,12 @@ 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 reporter : Reporter = {
727
+ log : ( txt : string ) => this . $logger . trace ( "Info.plist: " + txt ) ,
728
+ warn : ( txt : string ) => this . $logger . warn ( "Info.plist: " + txt ) ,
729
+ }
730
+
731
+ let session = new PlistSession ( reporter ) ;
727
732
let makePatch = ( plistPath : string ) => {
728
733
if ( ! this . $fs . exists ( plistPath ) ) {
729
734
this . $logger . trace ( "No plist found at: " + plistPath ) ;
@@ -743,17 +748,7 @@ We will now place an empty obsolete compatability white screen LauncScreen.xib f
743
748
makePatch ( pluginInfoPlistPath ) ;
744
749
}
745
750
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
- }
751
+ makePatch ( infoPlistPath ) ;
757
752
758
753
if ( projectData . projectId ) {
759
754
session . patch ( {
@@ -770,42 +765,36 @@ We will now place an empty obsolete compatability white screen LauncScreen.xib f
770
765
} ) ;
771
766
}
772
767
768
+ if ( ! buildOptions . release && projectData . projectId ) {
769
+ session . patch ( {
770
+ name : "CFBundleURLTypes from package.json nativescript.id" ,
771
+ read : ( ) =>
772
+ `<?xml version="1.0" encoding="UTF-8"?>
773
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
774
+ <plist version="1.0">
775
+ <dict>
776
+ <key>CFBundleURLTypes</key>
777
+ <array>
778
+ <dict>
779
+ <key>CFBundleTypeRole</key>
780
+ <string>Editor</string>
781
+ <key>CFBundleURLSchemes</key>
782
+ <array>
783
+ <string>${ projectData . projectId . replace ( / [ ^ A - Z a - z 0 - 9 ] / g, "" ) } </string>
784
+ </array>
785
+ </dict>
786
+ </array>
787
+ </dict>
788
+ </plist>`
789
+ } ) ;
790
+ }
791
+
773
792
let plistContent = session . build ( ) ;
774
793
775
794
this . $logger . trace ( "Info.plist: Write to: " + this . getPlatformData ( projectData ) . configurationFilePath ) ;
776
795
this . $fs . writeFile ( this . getPlatformData ( projectData ) . configurationFilePath , plistContent ) ;
777
796
}
778
797
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
798
private getAllInstalledPlugins ( projectData : IProjectData ) : Promise < IPluginData [ ] > {
810
799
return ( < IPluginsService > this . $injector . resolve ( "pluginsService" ) ) . getAllInstalledPlugins ( projectData ) ;
811
800
}
0 commit comments