diff --git a/src/Plugins/Compilers/IOSPluginCompiler.php b/src/Plugins/Compilers/IOSPluginCompiler.php index 4be73e1..6a26b92 100644 --- a/src/Plugins/Compilers/IOSPluginCompiler.php +++ b/src/Plugins/Compilers/IOSPluginCompiler.php @@ -359,19 +359,8 @@ protected function injectPlistEntries(string $plist, array $entries): string continue; } - // Handle array values - if (is_array($value)) { - $arrayContent = ''; - foreach ($value as $item) { - $item = $this->substituteEnvPlaceholders($item); - $arrayContent .= "\n\t\t{$item}"; - } - $entry = "\n\t{$key}\n\t{$arrayContent}\n\t"; - } else { - // Handle string values - substitute placeholders - $value = $this->substituteEnvPlaceholders($value); - $entry = "\n\t{$key}\n\t{$value}"; - } + // Handle plist types + $entry = $this->handlePlistTypes($key, $value); // Add before closing $plist = preg_replace( @@ -385,6 +374,41 @@ protected function injectPlistEntries(string $plist, array $entries): string return $plist; } + protected function handlePlistTypes($key, $value) + { + $entry = ""; + + if(is_string($key)){ + $entry = "\n\t{$key}"; + } + + // Handle array values + if (is_array($value)) { + $firstKey = array_key_first($value); + if(!is_int($firstKey)){ + $dictContent = ''; + foreach($value as $dictKey => $dictItem) { + $dictContent .= $this->handlePlistTypes($dictKey, $dictItem); + } + $entry .= "\n\t{$dictContent}\n\t"; + } else { + $arrayContent = ''; + foreach ($value as $arrKey => $arrItem) { + $arrayContent .= $this->handlePlistTypes($arrKey, $arrItem); + } + $entry .= "\n\t{$arrayContent}\n\t"; + } + } else if (is_bool($value)) { + $entry .= $value ? "\n\t" : ""; + } else { + // Handle string values - substitute placeholders + $value = $this->substituteEnvPlaceholders($value); + $entry .= "\n\t{$value}"; + } + + return $entry; + } + /** * Merge array values into an existing plist array entry */ diff --git a/tests/Feature/Plugins/IOSCompilerTest.php b/tests/Feature/Plugins/IOSCompilerTest.php index ae1b653..c6039f8 100644 --- a/tests/Feature/Plugins/IOSCompilerTest.php +++ b/tests/Feature/Plugins/IOSCompilerTest.php @@ -581,6 +581,17 @@ public function it_handles_various_plist_value_types(): void 'info_plist' => [ 'NSCameraUsageDescription' => 'Camera description', // String 'UIRequiredDeviceCapabilities' => ['arm64'], // Array (if supported) + 'UIApplicationSceneManifest' => [ // Dictionary with nested types + 'UIApplicationSupportsMultipleScenes' => true, + 'UISceneConfigurations' => [ + 'UIWindowSceneSessionRoleExternalDisplayNonInteractive' => [ + [ + 'UISceneConfigurationName' => 'External Display', + 'UISceneDelegateClassName' => 'NativePHP.SceneDelegate' + ] + ] + ] + ] ], ], ]); @@ -596,6 +607,10 @@ public function it_handles_various_plist_value_types(): void $this->assertStringContainsString('NSCameraUsageDescription', $content); $this->assertStringContainsString('Camera description', $content); + + $this->assertStringContainsString('UISceneConfigurationName', $content); + $this->assertStringContainsString('External Display', $content); + $this->assertStringContainsString('NativePHP.SceneDelegate', $content); } /**