@@ -7,7 +7,7 @@ module PrivacyManifestUtils
77 def self . add_aggregated_privacy_manifest ( installer )
88 user_project = get_user_project_from ( installer )
99 targets = get_application_targets ( user_project )
10- file_path = get_privacyinfo_file_path ( user_project )
10+ file_path = get_privacyinfo_file_path ( user_project , targets )
1111
1212 privacy_info = read_privacyinfo_file ( file_path ) || {
1313 "NSPrivacyCollectedDataTypes" => [ ] ,
@@ -70,13 +70,21 @@ def self.ensure_reference(file_path, user_project, target)
7070 reference_exists = target . resources_build_phase . files_references . any? { |file_ref | file_ref . path . end_with? "PrivacyInfo.xcprivacy" }
7171 unless reference_exists
7272 # We try to find the main group, but if it doesn't exist, we default to adding the file to the project root – both work
73- file_root = user_project . root_object . main_group . children . first { |group | group . name == target . name } || user_project
73+ file_root = user_project . root_object . main_group . children . find { |group |
74+ group . class == Xcodeproj ::Project ::Object ::PBXGroup && ( group . name == target . name || group . path == target . name )
75+ } || user_project
7476 file_ref = file_root . new_file ( file_path )
7577 build_file = target . resources_build_phase . add_file_reference ( file_ref , true )
7678 end
7779 end
7880
79- def self . get_privacyinfo_file_path ( user_project )
81+ def self . get_privacyinfo_file_path ( user_project , targets )
82+ file_refs = targets . flat_map { |target | target . resources_build_phase . files_references }
83+ existing_file = file_refs . find { |file_ref | file_ref . path . end_with? "PrivacyInfo.xcprivacy" }
84+ if existing_file
85+ return existing_file . real_path
86+ end
87+
8088 # We try to find a file we know exists in the project to get the path to the main group directory
8189 info_plist_path = user_project . files . find { |file_ref | file_ref . name == "Info.plist" }
8290 if info_plist_path . nil?
0 commit comments