@@ -743,40 +743,28 @@ We will now place an empty obsolete compatability white screen LauncScreen.xib f
743
743
makePatch ( pluginInfoPlistPath ) ;
744
744
}
745
745
746
- makePatch ( infoPlistPath ) ;
746
+ if ( ! buildOptions . release && projectData . projectId ) {
747
+ const modifiedPlistContent = this . updateCFBundleURLSchemes ( infoPlistPath , projectData ) ;
747
748
748
- if ( projectData . projectId ) {
749
749
session . patch ( {
750
- name : "CFBundleIdentifier from package.json nativescript.id" ,
751
- read : ( ) =>
752
- `<?xml version="1.0" encoding="UTF-8"?>
753
- <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
754
- <plist version="1.0">
755
- <dict>
756
- <key>CFBundleIdentifier</key>
757
- <string>${ projectData . projectId } </string>
758
- </dict>
759
- </plist>`
750
+ name : "CFBundleURLTypes from Info.plist and required one for restarting application" ,
751
+ read : ( ) => modifiedPlistContent
760
752
} ) ;
753
+
754
+ } else {
755
+ makePatch ( infoPlistPath ) ;
761
756
}
762
757
763
- if ( ! buildOptions . release && projectData . projectId ) {
758
+ if ( projectData . projectId ) {
764
759
session . patch ( {
765
- name : "CFBundleURLTypes from package.json nativescript.id" ,
760
+ name : "CFBundleIdentifier from package.json nativescript.id" ,
766
761
read : ( ) =>
767
762
`<?xml version="1.0" encoding="UTF-8"?>
768
763
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
769
764
<plist version="1.0">
770
765
<dict>
771
- <key>CFBundleURLTypes</key>
772
- <array>
773
- <dict>
774
- <key>CFBundleURLSchemes</key>
775
- <array>
776
- <string>${ projectData . projectId . replace ( / [ ^ A - Z a - z 0 - 9 ] / g, "" ) } </string>
777
- </array>
778
- </dict>
779
- </array>
766
+ <key>CFBundleIdentifier</key>
767
+ <string>${ projectData . projectId } </string>
780
768
</dict>
781
769
</plist>`
782
770
} ) ;
@@ -788,6 +776,36 @@ We will now place an empty obsolete compatability white screen LauncScreen.xib f
788
776
this . $fs . writeFile ( this . getPlatformData ( projectData ) . configurationFilePath , plistContent ) ;
789
777
}
790
778
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
+
791
809
private getAllInstalledPlugins ( projectData : IProjectData ) : Promise < IPluginData [ ] > {
792
810
return ( < IPluginsService > this . $injector . resolve ( "pluginsService" ) ) . getAllInstalledPlugins ( projectData ) ;
793
811
}
0 commit comments