From 752c173da529b48ead482be5088af6758f08ee65 Mon Sep 17 00:00:00 2001 From: Renaud Chaput Date: Wed, 29 May 2024 08:08:42 -0700 Subject: [PATCH] Fix Privacy Manifest generator when it does not contain a `NSPrivacyAccessedAPITypes` key (#44628) Summary: XCode privacy files might not contain a `NSPrivacyAccessedAPITypes` key, which causes the following error: ``` [!] An error occurred while processing the post-install hook of the Podfile. undefined method `each' for nil node_modules/react-native/scripts/cocoapods/privacy_manifest_utils.rb:111:in `block (4 levels) in get_used_required_reason_apis' node_modules/react-native/scripts/cocoapods/privacy_manifest_utils.rb:106:in `each' node_modules/react-native/scripts/cocoapods/privacy_manifest_utils.rb:106:in `block (3 levels) in get_used_required_reason_apis' ``` [IOS] [FIXED] - Privacy Manifest aggregation failing due to no `NSPrivacyAccessedAPITypes` key Pull Request resolved: https://github.com/facebook/react-native/pull/44628 Test Plan: I tested this patch on our own app and it solved the issue. Reviewed By: christophpurrer Differential Revision: D57618425 Pulled By: cipolleschi fbshipit-source-id: 1a36ab5a1bb45b8507d3663b782c95258d97c8a4 --- .../scripts/cocoapods/privacy_manifest_utils.rb | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/packages/react-native/scripts/cocoapods/privacy_manifest_utils.rb b/packages/react-native/scripts/cocoapods/privacy_manifest_utils.rb index 7fcc3d339cc..42ce104571a 100644 --- a/packages/react-native/scripts/cocoapods/privacy_manifest_utils.rb +++ b/packages/react-native/scripts/cocoapods/privacy_manifest_utils.rb @@ -108,11 +108,12 @@ module PrivacyManifestUtils if File.basename(file_path) == 'PrivacyInfo.xcprivacy' content = Xcodeproj::Plist.read_from_path(file_path) accessed_api_types = content["NSPrivacyAccessedAPITypes"] - accessed_api_types.each do |accessed_api| - api_type = accessed_api["NSPrivacyAccessedAPIType"] - reasons = accessed_api["NSPrivacyAccessedAPITypeReasons"] - used_apis[api_type] ||= [] - used_apis[api_type] += reasons + accessed_api_types&.each do |accessed_api| + api_type = accessed_api["NSPrivacyAccessedAPIType"] + reasons = accessed_api["NSPrivacyAccessedAPITypeReasons"] + next unless api_type + used_apis[api_type] ||= [] + used_apis[api_type] += reasons end end end