From aceb8671a6bb3c382c88e95d17bc867b00ee336e Mon Sep 17 00:00:00 2001 From: Shahroz Khan Date: Tue, 1 Dec 2026 04:42:28 -0500 Subject: [PATCH 1/3] fix: stop pod install on React Native before 0.79 and when no install hook can run Below React Native 0.79, React Native doesn't register the SDK's TurboModules on iOS, so a 0.77 or 0.78 app (or Expo SDK 52, on 0.76) built and the SDK silently did nothing there. `pod install` now stops below 0.79 when it installs the SDK's pod. The version comes from the package.json at REACT_NATIVE_PATH, which `use_react_native!` exports and React Native's own pod scripts read. The check runs from the install hooks, before CocoaPods' target checks, because React Native's autolinking evaluates the podspec before `use_react_native!` sets the path. It compares major and minor only, so release candidates and nightlies of 0.79 and later pass; an npm peer range would reject them. The CocoaPods installer hook quietly skipped itself when `Pod::Installer` lacked the private `validate_targets` or `run_podfile_post_install_hooks` step. If React Native's SPMManager wasn't loaded either, nothing added customerio-ios to the pods, `pod install` succeeded, and the build failed later with `No such module`. That case now stops `pod install`, naming the missing step and the supported CocoaPods range (1.13 to 1.17, which all have both steps). Co-Authored-By: Claude Opus 5.5 --- ios/cocoapods_swift_packages.rb | 49 +++++++++- scripts/test_cocoapods_swift_packages.rb | 114 +++++++++++++++++++++++ 2 files changed, 159 insertions(+), 4 deletions(-) diff --git a/ios/cocoapods_swift_packages.rb b/ios/cocoapods_swift_packages.rb index 49eb090a..335ba20b 100644 --- a/ios/cocoapods_swift_packages.rb +++ b/ios/cocoapods_swift_packages.rb @@ -1,5 +1,8 @@ # frozen_string_literal: true +require 'json' +require 'pathname' + # The podspecs can reach this file through different paths (a pnpm or symlinked node_modules and its real path), and # Ruby 2.6 loads it once per path. Keep the first copy: its registrations, constants and hooks. return if defined?(CustomerIO::SwiftPackages) @@ -55,6 +58,11 @@ module SwiftPackages 'CustomerIOMessagingPushFCM' => FCM_SWITCH, 'CioFirebaseWrapper' => FCM_SWITCH, }.freeze + # Below 0.79, React Native doesn't register the SDK's TurboModules on iOS, so the app builds and the SDK does + # nothing there. + MINIMUM_REACT_NATIVE = [0, 79].freeze + # The private CocoaPods installer steps InstallerHook overrides. CocoaPods 1.13 to 1.17 have both. + INSTALLER_STEPS = %i[validate_targets run_podfile_post_install_hooks].freeze @registrations = {} @@ -101,10 +109,20 @@ def register(spec_or_name, version:, products:, subspecs: {}, push_provider: nil # React Native's list, then wires them in), and CocoaPods' installer (refuses trunk pods before CocoaPods' # own target checks, and wires the pods in after the Podfile's post_install if React Native didn't). def install_hook - if defined?(::Pod::Installer) && !::Pod::Installer.ancestors.include?(InstallerHook) && - ::Pod::Installer.private_method_defined?(:validate_targets) && - ::Pod::Installer.private_method_defined?(:run_podfile_post_install_hooks) - ::Pod::Installer.prepend(InstallerHook) + if defined?(::Pod::Installer) + missing_steps = INSTALLER_STEPS.reject { |step| ::Pod::Installer.private_method_defined?(step) } + if missing_steps.empty? + ::Pod::Installer.prepend(InstallerHook) unless ::Pod::Installer.ancestors.include?(InstallerHook) + elsif !defined?(::SPMManager) + # Raised while CocoaPods evaluates the podspec: no later step of this install is known to run our code. + version = defined?(::Pod::VERSION) ? ::Pod::VERSION : 'this version' + raise Pod::Informative, "customerio-reactnative can't add customerio-ios to its pods with CocoaPods " \ + "#{version}: its installer has no #{missing_steps.map { |s| "`#{s}`" }.join(' or ')} " \ + "step, and React Native's SPMManager (behind `spm_dependency`) isn't loaded. " \ + 'The build would then fail with `No such module` for customerio-ios modules. Use ' \ + 'CocoaPods 1.13 to 1.17 (React Native excludes 1.15.0 and 1.15.1), or report ' \ + 'this with your CocoaPods version: https://github.com/customerio/customerio-reactnative/issues' + end end return unless defined?(::SPMManager) return if ::SPMManager.ancestors.include?(SPMManagerHook) @@ -112,6 +130,27 @@ def install_hook ::SPMManager.prepend(SPMManagerHook) end + # `use_react_native!` exports REACT_NATIVE_PATH while CocoaPods reads the Podfile (relative to the Podfile's + # folder or absolute, depending on the React Native version), and React Native's pod scripts read its version + # from the package.json there. That's why this runs from the install hooks: React Native's autolinking + # evaluates the podspec before `use_react_native!`. Major and minor only, so release candidates and nightlies of + # a supported version pass. An install without the SDK's own pod (an extension's rich push pod) isn't checked. + def refuse_unsupported_react_native!(installer, react_native_path = ENV['REACT_NATIVE_PATH'], podfile_folder = nil) + return if react_native_path.to_s.empty? + return unless installer.pod_targets.any? { |t| t.pod_name == 'customerio-reactnative' } + + path = Pathname.new(react_native_path) + path = Pathname.new(podfile_folder || ::Pod::Config.instance.installation_root) + path if path.relative? + version = JSON.parse(File.read(path + 'package.json'))['version'].to_s + return if (version.split('.').first(2).map(&:to_i) <=> MINIMUM_REACT_NATIVE) >= 0 + + minimum = MINIMUM_REACT_NATIVE.join('.') + raise Pod::Informative, "customerio-reactnative needs React Native #{minimum} or later on iOS, and this app has " \ + "React Native #{version}. Before #{minimum}, React Native doesn't register the SDK's " \ + 'native modules, so the app would build and the SDK would do nothing on iOS. Update ' \ + 'React Native (Expo SDK 53 or later for Expo apps), then run `pod install` again.' + end + # With `incremental_installation`, CocoaPods keeps a target whose inputs didn't change, but whether apply! # flattens a static target depends on how many static variants of its pod the install has. When a target in the # last generated project was flattened the other way (one static variant became two, or two became one), its kept @@ -142,6 +181,7 @@ def apply!(installer) return if @applied_to.equal?(installer) @applied_to = installer + refuse_unsupported_react_native!(installer) refuse_trunk_pods!(installer) refuse_conflicting_push!(installer) # With `skip_pods_project_generation`, CocoaPods generates no projects, so whatever builds the pods adds the @@ -360,6 +400,7 @@ module InstallerHook # CocoaPods' own checks would otherwise reject some trunk pods first (CioFirebaseWrapper defines no module # map), with a message that says nothing about what replaces them. def validate_targets + CustomerIO::SwiftPackages.refuse_unsupported_react_native!(self) CustomerIO::SwiftPackages.refuse_trunk_pods!(self) CustomerIO::SwiftPackages.refuse_rich_push_in_app!(self) CustomerIO::SwiftPackages.refuse_conflicting_push!(self) diff --git a/scripts/test_cocoapods_swift_packages.rb b/scripts/test_cocoapods_swift_packages.rb index 84b93ce0..415aec02 100644 --- a/scripts/test_cocoapods_swift_packages.rb +++ b/scripts/test_cocoapods_swift_packages.rb @@ -76,6 +76,8 @@ def xcconfig_path(name) def setup @dir = Dir.mktmpdir + # React Native's use_react_native! exports it; a value from the shell mustn't reach these tests. + @react_native_path = ENV.delete('REACT_NATIVE_PATH') registrations.clear %i[$customerio_location_enabled $customerio_geofence_enabled $customerio_live_activities_enabled $customerio_push_provider].each do |name| @@ -85,6 +87,7 @@ def setup def teardown FileUtils.rm_rf(@dir) + ENV['REACT_NATIVE_PATH'] = @react_native_path end def registrations @@ -202,6 +205,57 @@ def install_modules_dependencies(_spec); end JSON.parse(output.lines.last) end + # React Native version + + # Writes /node_modules/react-native/package.json with this version and returns that folder. + def react_native(version) + folder = File.join(@dir, 'node_modules', 'react-native') + FileUtils.mkdir_p(folder) + File.write(File.join(folder, 'package.json'), JSON.generate(name: 'react-native', version: version)) + folder + end + + def sdk_install + installer([pod_target('customerio-reactnative')], nil) + end + + # Older React Native exports the path as the Podfile gave it, relative to the Podfile's folder. + def test_refuses_react_native_before_0_79 + react_native('0.78.3') + error = assert_raises(Pod::Informative) do + CustomerIO::SwiftPackages.refuse_unsupported_react_native!(sdk_install, '../node_modules/react-native', + File.join(@dir, 'ios')) + end + assert_match(/needs React Native 0\.79 or later on iOS, and this app has React Native 0\.78\.3\./, error.message) + end + + # Release candidates and nightlies of 0.79 and later pass, as npm's peer ranges wouldn't let them. + def test_accepts_react_native_0_79_and_later_including_prereleases + %w[0.79.0-rc.3 0.79.7 0.88.0 0.90.0-nightly-20261120-0123abcdef 1000.0.0].each do |version| + CustomerIO::SwiftPackages.refuse_unsupported_react_native!(sdk_install, react_native(version)) + end + end + + # A Notification Service Extension's rich push pod doesn't need React Native, and a Podfile that doesn't call + # use_react_native! exports no path. + def test_an_install_without_the_sdk_pod_or_react_native_isnt_checked + folder = react_native('0.78.3') + extension = installer([pod_target('customerio-reactnative-richpush', pod_name: 'customerio-reactnative-richpush')], nil) + CustomerIO::SwiftPackages.refuse_unsupported_react_native!(extension, folder) + CustomerIO::SwiftPackages.refuse_unsupported_react_native!(sdk_install, nil) + end + + # React Native's autolinking evaluates the podspec before use_react_native! exports the path, so the install hook + # checks, before CocoaPods' own target checks. + def test_the_installer_hook_refuses_react_native_before_0_79 + ENV['REACT_NATIVE_PATH'] = react_native('0.77.3') + install = FakeInstaller.new([pod_target('customerio-reactnative')]) + install.singleton_class.prepend(CustomerIO::SwiftPackages::InstallerHook) + error = assert_raises(Pod::Informative) { install.send(:validate_targets) } + assert_match(/this app has React Native 0\.77\.3/, error.message) + assert_nil install.validated + end + # The two podspecs can load the module through different paths (pnpm: the real path and node_modules' symlink), which # Ruby 2.6 loads twice. The second load must keep the first pod's registration. def test_loading_through_a_second_path_keeps_registrations @@ -636,6 +690,66 @@ def test_cocoapods_post_install_applies_when_react_native_did_not assert_equal 2, target.package_product_dependencies.size end + # Registers a pod in a child process whose CocoaPods installer has only the given private steps, with or without + # React Native's SPMManager, and returns the hooked classes or the install's error. + def register_with(installer_steps:, spm_manager:) + script = <<~RUBY + module Pod + VERSION = '1.99.0' + class Informative < StandardError; end + class Installer + private + + #{installer_steps.map { |step| "def #{step}; end" }.join("\n")} + end + end + #{'class SPMManager; end' if spm_manager} + load ARGV[0] + begin + CustomerIO::SwiftPackages.register('customerio-reactnative-richpush', version: '5.4.0', products: []) + hooked = [Pod::Installer, (SPMManager if defined?(SPMManager))].compact.select do |klass| + klass.ancestors.any? { |mod| mod.name.to_s.start_with?('CustomerIO::') } + end + puts "hooked: \#{hooked.join(',')}" + rescue Pod::Informative => e + puts e.message + end + RUBY + output, status = Open3.capture2e(RbConfig.ruby, '-e', script, File.join(REPO_ROOT, 'ios', 'cocoapods_swift_packages.rb')) + assert status.success?, output + output.strip + end + + def test_cocoapods_with_its_installer_steps_gets_the_hook + assert_equal 'hooked: Pod::Installer', + register_with(installer_steps: %i[validate_targets run_podfile_post_install_hooks], spm_manager: false) + end + + def test_without_the_installer_steps_react_natives_spm_manager_keeps_the_install_going + assert_equal 'hooked: SPMManager', register_with(installer_steps: [], spm_manager: true) + end + + # Neither hook would add customerio-ios, so the app would only fail to build later. + def test_pod_install_stops_when_neither_hook_can_run + steps = { validate_targets: :run_podfile_post_install_hooks, run_podfile_post_install_hooks: :validate_targets } + steps.each do |present, missing| + output = register_with(installer_steps: [present], spm_manager: false) + assert_match(/with CocoaPods 1\.99\.0: its installer has no `#{missing}` step/, output) + assert_match(/Use CocoaPods 1\.13 to 1\.17/, output) + end + end + + # Without CocoaPods' installer steps, React Native's post_install is the only hook, and it checks too. + def test_react_natives_hook_refuses_react_native_before_0_79 + ENV['REACT_NATIVE_PATH'] = react_native('0.78.3') + manager = FakeSPMManager.new + manager.singleton_class.prepend(CustomerIO::SwiftPackages::SPMManagerHook) + error = assert_raises(Pod::Informative) do + manager.apply_on_post_install(installer([pod_target('customerio-reactnative')], project)) + end + assert_match(/this app has React Native 0\.78\.3/, error.message) + end + def test_the_hook_takes_our_pods_out_of_react_natives_list registrations['customerio-reactnative'] = MAIN manager = FakeSPMManager.new From 0bc0ca729f92bc2967dd54c73463f3470fcb5f42 Mon Sep 17 00:00:00 2001 From: Shahroz Khan Date: Tue, 1 Dec 2026 05:25:41 -0500 Subject: [PATCH 2/3] docs: troubleshoot the pod install error below React Native 0.79 Adds a migration guide troubleshooting entry for the new `pod install` error on React Native below 0.79: what it means (the SDK's TurboModules don't register there, so the SDK would do nothing on iOS) and the fix (React Native 0.79 or later, Expo SDK 53 or later). Co-Authored-By: Claude Opus 5.5 --- docs/migrate-7-to-8.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/docs/migrate-7-to-8.md b/docs/migrate-7-to-8.md index 7c260dec..b82600e5 100644 --- a/docs/migrate-7-to-8.md +++ b/docs/migrate-7-to-8.md @@ -276,6 +276,11 @@ last sync at all, so run `spm update` in that case. `CustomerIOLiveActivities`, `CustomerIOMessagingPushAPN`, `CustomerIOMessagingPushFCM`, `CioFirebaseWrapper`), turn that module or push provider on with its subspec or Podfile global instead (A1), or it leaves the app. The error lists the switch for each one. +- **`pod install` stops with "customerio-reactnative needs React Native 0.79 or later on iOS"**: below 0.79, + React Native doesn't register the SDK's TurboModules on iOS, so the app would build and the SDK would do nothing + there (7.x behaves the same). Update React Native to 0.79 or later (Expo SDK 53 or later for Expo apps), then run + `pod install` again. The version comes from the `package.json` in the React Native folder your Podfile's + `use_react_native!` points at. - **`pod install` stops because an app target installs customerio-reactnative-richpush, or CocoaPods finds two sources for it**: your app gets the SDK from a folder not named `customerio-reactnative` (a workspace package or a `file:` link), and React Native's autolinking took the rich push podspec, as 7.x's did. Name From fd2669295688f12ebdafdc7c3547ef2a7e272a1d Mon Sep 17 00:00:00 2001 From: Shahroz Khan Date: Tue, 1 Dec 2026 10:43:11 -0500 Subject: [PATCH 3/3] fix: update Customer.io iOS SDK to 5.4.1 5.4.1 allows swift-eventsource 3.4.x, so apps that also use LaunchDarkly 11.7.0 or later can resolve packages. Co-Authored-By: Claude Opus 5.5 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 9cc05c7e..9b9abe18 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,7 @@ }, "./package.json": "./package.json" }, - "cioNativeiOSSdkVersion": "= 5.4.0", + "cioNativeiOSSdkVersion": "= 5.4.1", "files": [ "src", "lib",