Skip to content

Commit 0452f55

Browse files
philIipfacebook-github-bot
authored andcommitted
adjust ats settings in plist in pod install (#38086)
Summary: Pull Request resolved: #38086 Changelog: [Internal] in this diff, we update the developer's Info.plists to have the correct ATS settings introducing usage of files: https://www.rubydoc.info/github/CocoaPods/Xcodeproj/Xcodeproj/Project#files-instance_method, in order to retrieve the plists Differential Revision: D47041590 fbshipit-source-id: 03a2d8759c50f58a2364c96f30900a44e47b3328
1 parent 6c74352 commit 0452f55

File tree

3 files changed

+41
-2
lines changed

3 files changed

+41
-2
lines changed

packages/react-native/scripts/cocoapods/utils.rb

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,42 @@ def self.set_imagemanager_search_path(target_installation_result)
396396
])
397397
end
398398

399+
def self.get_plist_paths_from(user_project)
400+
info_plists = user_project
401+
.files
402+
.select { |p|
403+
p.name&.end_with?('Info.plist')
404+
}
405+
return info_plists
406+
end
407+
408+
def self.update_ats_in_plist(plistPaths, parent)
409+
plistPaths.each do |plistPath|
410+
fullPlistPath = File.join(parent, plistPath.path)
411+
plist = Xcodeproj::Plist.read_from_path(fullPlistPath)
412+
ats_configs = {
413+
"NSAllowsArbitraryLoads" => false,
414+
"NSAllowsLocalNetworking" => true,
415+
}
416+
if plist.nil?
417+
plist = {
418+
"NSAppTransportSecurity" => ats_configs
419+
}
420+
else
421+
plist["NSAppTransportSecurity"] = ats_configs
422+
end
423+
Xcodeproj::Plist.write_to_path(plist, fullPlistPath)
424+
end
425+
end
426+
427+
def self.apply_ats_config(installer)
428+
user_project = installer.aggregate_targets
429+
.map{ |t| t.user_project }
430+
.first
431+
plistPaths = self.get_plist_paths_from(user_project)
432+
self.update_ats_in_plist(plistPaths, user_project.path.parent)
433+
end
434+
399435
def self.react_native_pods
400436
return [
401437
"DoubleConversion",

packages/react-native/scripts/react_native_pods.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ def react_native_post_install(
246246
ReactNativePodsUtils.set_node_modules_user_settings(installer, react_native_path)
247247
ReactNativePodsUtils.apply_flags_for_fabric(installer, fabric_enabled: fabric_enabled)
248248
ReactNativePodsUtils.apply_xcode_15_patch(installer)
249+
ReactNativePodsUtils.apply_ats_config(installer)
249250

250251
NewArchitectureHelper.set_clang_cxx_language_standard_if_needed(installer)
251252
is_new_arch_enabled = ENV['RCT_NEW_ARCH_ENABLED'] == "1"

packages/rn-tester/RNTester/Info.plist

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,14 @@
3838
<key>NSAppTransportSecurity</key>
3939
<dict>
4040
<key>NSAllowsArbitraryLoads</key>
41+
<false/>
42+
<key>NSAllowsLocalNetworking</key>
4143
<true/>
4244
</dict>
4345
<key>NSLocationWhenInUseUsageDescription</key>
4446
<string>You need to add NSLocationWhenInUseUsageDescription key in Info.plist to enable geolocation, otherwise it is going to *fail silently*!</string>
47+
<key>NSPhotoLibraryUsageDescription</key>
48+
<string>You need to add NSPhotoLibraryUsageDescription key in Info.plist to enable photo library usage, otherwise it is going to *fail silently*!</string>
4549
<key>UILaunchStoryboardName</key>
4650
<string>LaunchScreen</string>
4751
<key>UIRequiredDeviceCapabilities</key>
@@ -57,7 +61,5 @@
5761
</array>
5862
<key>UIViewControllerBasedStatusBarAppearance</key>
5963
<false/>
60-
<key>NSPhotoLibraryUsageDescription</key>
61-
<string>You need to add NSPhotoLibraryUsageDescription key in Info.plist to enable photo library usage, otherwise it is going to *fail silently*!</string>
6264
</dict>
6365
</plist>

0 commit comments

Comments
 (0)