From 250ddeee0bd93cfee1add40fd6371a702e9f5964 Mon Sep 17 00:00:00 2001 From: Fadi George Date: Fri, 20 Nov 2026 11:35:49 -0800 Subject: [PATCH 1/2] feat: [SDK-5818] add Package.swift for React Native SPM mode Ship a Swift package manifest so apps using React Native's Swift Package Manager mode can link the SDK and OneSignal-XCFramework. Location is omitted when ONESIGNAL_DISABLE_LOCATION is set, matching the podspec. The release workflow bumps the XCFramework pin in both files, and a test keeps them in sync. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/create-release-pr.yml | 7 +++ Package.swift | 60 +++++++++++++++++++++++++ README.md | 8 ++++ __tests__/packageSwift.test.ts | 30 +++++++++++++ package.json | 6 ++- 5 files changed, 110 insertions(+), 1 deletion(-) create mode 100644 Package.swift create mode 100644 __tests__/packageSwift.test.ts diff --git a/.github/workflows/create-release-pr.yml b/.github/workflows/create-release-pr.yml index 2e7e4147..6707a81c 100644 --- a/.github/workflows/create-release-pr.yml +++ b/.github/workflows/create-release-pr.yml @@ -175,6 +175,13 @@ jobs: fi echo "✓ Updated react-native-onesignal.podspec with iOS SDK ${VERSION}" + sed -i '' -E "s/(let oneSignalXCFrameworkVersion: Version = \")[^\"]+(\")/\1$VERSION\2/" Package.swift + if ! grep -q "let oneSignalXCFrameworkVersion: Version = \"${VERSION}\"" Package.swift; then + echo "::error::Failed to update iOS SDK version in Package.swift to ${VERSION}" + exit 1 + fi + echo "✓ Updated Package.swift with iOS SDK ${VERSION}" + PODFILE=examples/demo/ios/Podfile sed -i '' -E "s/^([[:space:]]*pod 'OneSignalXCFramework', )'[^']+'.*$/\1'${VERSION}'/" "$PODFILE" if [ "$(grep -c "pod 'OneSignalXCFramework', '${VERSION}'$" "$PODFILE")" -ne 2 ]; then diff --git a/Package.swift b/Package.swift new file mode 100644 index 00000000..145b1f7b --- /dev/null +++ b/Package.swift @@ -0,0 +1,60 @@ +// swift-tools-version: 6.0 + +import Foundation +import PackageDescription + +func oneSignalEnvFlag(_ name: String) -> Bool { + let value = Context.environment[name]?.trimmingCharacters(in: .whitespacesAndNewlines).lowercased() + return value == "true" || value == "1" +} + +let oneSignalDisableLocation = oneSignalEnvFlag("ONESIGNAL_DISABLE_LOCATION") + +// Keep in sync with onesignal_xcframework_version in react-native-onesignal.podspec. +let oneSignalXCFrameworkVersion: Version = "5.8.1" + +// InAppMessages and Location are separate library products in OneSignal-XCFramework +// and must be linked explicitly under SPM. +var oneSignalDependencies: [Target.Dependency] = [ + .product(name: "OneSignalFramework", package: "OneSignal-XCFramework"), + .product(name: "OneSignalInAppMessages", package: "OneSignal-XCFramework"), +] + +if !oneSignalDisableLocation { + oneSignalDependencies.append(.product(name: "OneSignalLocation", package: "OneSignal-XCFramework")) +} + +let package = Package( + name: "ReactNativeOneSignal", + platforms: [.iOS("15.1")], + products: [ + .library(name: "ReactNativeOneSignal", targets: ["ReactNativeOneSignal"]), + ], + dependencies: [ + // Local packages generated per app by React Native's SwiftPM autolinker, + // relative to where it places this package. + .package(name: "ReactNative", path: "../../../../xcframeworks"), + .package(name: "React-GeneratedCode", path: "../../../ios"), + .package(url: "https://github.com/OneSignal/OneSignal-XCFramework", exact: oneSignalXCFrameworkVersion), + ], + targets: [ + .target( + name: "ReactNativeOneSignal", + dependencies: [ + .product(name: "ReactHeaders", package: "ReactNative"), + .product(name: "ReactNativeHeaders", package: "ReactNative"), + .product(name: "ReactNativeDependenciesHeaders", package: "ReactNative"), + .product(name: "ReactAppHeaders", package: "React-GeneratedCode"), + ] + oneSignalDependencies, + path: "ios/RCTOneSignal", + publicHeadersPath: ".", + cSettings: [.define("RCT_NEW_ARCH_ENABLED", to: "1")], + cxxSettings: [ + .define("RCT_NEW_ARCH_ENABLED", to: "1"), + .define("DEBUG", .when(configuration: .debug)), + .define("NDEBUG", .when(configuration: .release)), + ] + ), + ], + cxxLanguageStandard: .cxx20 +) diff --git a/README.md b/README.md index 4cbbe976..56f49a34 100755 --- a/README.md +++ b/README.md @@ -31,6 +31,12 @@ If you run into any challenges or have concerns, please contact our support team See the [Setup Guide](https://documentation.onesignal.com/docs/react-native-sdk-setup) for setup instructions. +#### Swift Package Manager (iOS) + +This package ships a `Package.swift` for React Native's Swift Package Manager mode (React Native `0.87` and later). In that mode it is the Swift package `ReactNativeOneSignal`, which brings in `OneSignal-XCFramework` at the same version the podspec uses. Run `npx react-native spm add` (or `npx react-native spm update` if SPM is already set up) after installing. CocoaPods apps are unaffected. + +A Notification Service Extension target is not managed by React Native's autolinker. Add the `OneSignalExtension` product from `https://github.com/OneSignal/OneSignal-XCFramework` to it in Xcode, at the same version. + #### Disable Location Module By default, `react-native-onesignal` includes OneSignal's native location module so `OneSignal.Location` works without extra setup. If your app does not use location features, you can exclude the native location module from iOS and Android builds. @@ -71,6 +77,8 @@ ONESIGNAL_DISABLE_LOCATION=true pod install Gradle re-reads the environment variable or `onesignal.disableLocation` property on each configuration, so a clean build after changing the flag is enough on Android. +With Swift Package Manager, `Package.swift` reads the variable when packages are resolved. Export it in the shell that runs `npx react-native spm update` and `xcodebuild` (or launches Xcode), then run File > Packages > Reset Package Caches in Xcode after changing it. + > [!IMPORTANT] > When using Xcode or Android Studio, launch the IDE from a terminal that has `ONESIGNAL_DISABLE_LOCATION` exported. An IDE launched from the Dock/Finder does not inherit variables set only in your shell profile. On CI, key any CocoaPods / Gradle caches on the value of `ONESIGNAL_DISABLE_LOCATION` so a restored cache does not resurrect the location module. diff --git a/__tests__/packageSwift.test.ts b/__tests__/packageSwift.test.ts new file mode 100644 index 00000000..32c528b3 --- /dev/null +++ b/__tests__/packageSwift.test.ts @@ -0,0 +1,30 @@ +/// + +import { readFileSync } from 'node:fs'; +import path from 'node:path'; + +import { expect, test } from 'vite-plus/test'; + +// CI does not build Package.swift, so keep its native dependency pinned to the podspec's. +const root = path.resolve(import.meta.dirname, '..'); +const read = (file: string) => readFileSync(path.join(root, file), 'utf8'); + +test('Package.swift pins the same OneSignal-XCFramework version as the podspec', () => { + const podspecVersion = read('react-native-onesignal.podspec').match( + /onesignal_xcframework_version = '([^']+)'/, + )?.[1]; + const packageSwiftVersion = read('Package.swift').match( + /let oneSignalXCFrameworkVersion: Version = "([^"]+)"/, + )?.[1]; + + expect(podspecVersion).toBeDefined(); + expect(packageSwiftVersion).toBe(podspecVersion); +}); + +test('swiftpmConfig name matches the Package.swift product', () => { + const { swiftpmConfig } = JSON.parse(read('package.json')) as { + swiftpmConfig: { name: string }; + }; + + expect(read('Package.swift')).toContain(`.library(name: "${swiftpmConfig.name}"`); +}); diff --git a/package.json b/package.json index 92bfae94..b345086e 100644 --- a/package.json +++ b/package.json @@ -30,7 +30,8 @@ "android/build.gradle", "android/proguard-rules.pro", "ios", - "react-native-onesignal.podspec" + "react-native-onesignal.podspec", + "Package.swift" ], "main": "dist/index.js", "types": "dist/index.d.ts", @@ -73,5 +74,8 @@ "OneSignal": "RCTOneSignalEventEmitter" } } + }, + "swiftpmConfig": { + "name": "ReactNativeOneSignal" } } From a97e37ceeafae63e043fb2d65dc8274b351d20b3 Mon Sep 17 00:00:00 2001 From: Fadi George Date: Fri, 20 Nov 2026 18:07:17 -0800 Subject: [PATCH 2/2] docs: [SDK-5818] mention SwiftPM and DerivedData caches in the location CI note Co-Authored-By: Claude Opus 5.5 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 56f49a34..c7efb772 100755 --- a/README.md +++ b/README.md @@ -80,7 +80,7 @@ Gradle re-reads the environment variable or `onesignal.disableLocation` property With Swift Package Manager, `Package.swift` reads the variable when packages are resolved. Export it in the shell that runs `npx react-native spm update` and `xcodebuild` (or launches Xcode), then run File > Packages > Reset Package Caches in Xcode after changing it. > [!IMPORTANT] -> When using Xcode or Android Studio, launch the IDE from a terminal that has `ONESIGNAL_DISABLE_LOCATION` exported. An IDE launched from the Dock/Finder does not inherit variables set only in your shell profile. On CI, key any CocoaPods / Gradle caches on the value of `ONESIGNAL_DISABLE_LOCATION` so a restored cache does not resurrect the location module. +> When using Xcode or Android Studio, launch the IDE from a terminal that has `ONESIGNAL_DISABLE_LOCATION` exported. An IDE launched from the Dock/Finder does not inherit variables set only in your shell profile. On CI, key any CocoaPods, SwiftPM, Xcode DerivedData, and Gradle caches on the value of `ONESIGNAL_DISABLE_LOCATION` so a restored cache does not resurrect the location module. #### Change Log