Skip to content

feat: add Swift Package Manager support for iOS plugin#1131

Merged
fadi-george merged 17 commits intomainfrom
fadi/sdk-3401-feedback-add-flutter-swift-package-manager-support
Apr 1, 2026
Merged

feat: add Swift Package Manager support for iOS plugin#1131
fadi-george merged 17 commits intomainfrom
fadi/sdk-3401-feedback-add-flutter-swift-package-manager-support

Conversation

@fadi-george
Copy link
Copy Markdown
Collaborator

@fadi-george fadi-george commented Mar 30, 2026

Description

One Line Summary

Add Swift Package Manager (SPM) support for the iOS plugin while maintaining full CocoaPods compatibility.

Screenshot 2026-03-30 at 1 05 26 PM Screenshot 2026-03-31 at 5 20 05 PM Screenshot 2026-03-31 at 5 15 59 PM

Details

Motivation

Flutter is gradually adopting Swift Package Manager as the default dependency manager for iOS. Plugins that don't support SPM can cause build problems for projects that have migrated to SPM. This change ensures the OneSignal Flutter plugin works with both CocoaPods and SPM, following Flutter's official migration guide.

Scope

Plugin iOS source restructure (ios/):

The core change restructures the iOS plugin source files from ios/Classes/ to the SPM-compatible directory layout at ios/onesignal_flutter/:

ios/
├── onesignal_flutter.podspec         (updated paths)
└── onesignal_flutter/
    ├── Package.swift                 (NEW — SPM package definition)
    └── Sources/
        └── onesignal_flutter/
            ├── *.m                   (implementation files)
            └── include/
                └── onesignal_flutter/
                    └── *.h           (public headers)

Key details:

  • Package.swift — Declares the SPM package targeting iOS 11.0, depending on OneSignal-iOS-SDK exact version 5.5.0 via SPM. Library name is onesignal-flutter (underscores to hyphens per Flutter convention). Depends on OneSignalFramework, OneSignalInAppMessages, OneSignalLocation, and OneSignalExtension products.
  • Header files moved from ios/Classes/*.hios/onesignal_flutter/Sources/onesignal_flutter/include/onesignal_flutter/ (SPM public headers directory).
  • Implementation files moved from ios/Classes/*.mios/onesignal_flutter/Sources/onesignal_flutter/.
  • #import statements in all .m files updated to use relative paths (./include/onesignal_flutter/HeaderName.h) since headers are now in a subdirectory.
  • onesignal_flutter.podspec updated source_files and public_header_files to point to new paths — CocoaPods continues to work with the same files.
  • ios/Classes/ and ios/Assets/ (empty) directories removed.

What is NOT changed:

  • No public API changes (Dart or native)
  • No changes to Android plugin
  • No changes to the CocoaPods dependency (OneSignalXCFramework 5.5.0)
  • No changes to the demo example app (remains CocoaPods-based)

examples/demo_spm/ — SPM example app:

Scaffolded the existing demo_spm stub into a full example app with ios/ and android/ platform folders. This app uses SPM for iOS dependency resolution (no Podfile). Includes a OneSignalNotificationServiceExtension target configured with the OneSignalExtension SPM product for push notification processing.

Testing

Prerequisites

Enable Swift Package Manager in Flutter (one-time setup):

flutter config --enable-swift-package-manager

1. CocoaPods build (examples/demo/)

demo has enable-swift-package-manager: false in its pubspec.yaml to ensure CocoaPods is used.

  • Ran flutter run on iOS simulator
  • Tested all workflows: notifications, in-app messages, tags, aliases, email/SMS, location, Live Activities
  • Pod install resolves correctly with updated podspec paths

2. SPM build (examples/demo_spm/)

Wiped simulator, then ran flutter run on iOS simulator.

  • No Podfile — dependencies resolve entirely via SPM
  • OneSignal-iOS-SDK 5.5.0 resolves via SPM
  • Tested all workflows: notifications, in-app messages, tags, aliases, email/SMS, location, Live Activities

3. CocoaPods → SPM migration (examples/demo/)

Wiped simulator, then tested migrating demo from CocoaPods to SPM:

  1. Comment out the SPM disable config in pubspec.yaml:
    # config:
    #   enable-swift-package-manager: false
  2. Delete Podfile and Pods/ directory
  3. Remove the CocoaPods include line from ios/Flutter/Debug.xcconfig and ios/Flutter/Release.xcconfig:
    #include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"
    
  4. Run flutter run — Flutter adds SPM integration and builds successfully
  5. Tested all workflows: notifications, in-app messages, tags, aliases, email/SMS, location, Live Activities

Notes

  • No unit tests added — this is a build system / packaging change with no logic changes
  • Existing Dart unit tests continue to pass

Affected code checklist

  • Notifications
  • Outcomes
  • Sessions
  • In-App Messaging
  • REST API requests
  • Public API changes

None of the above are affected. This is a build system change only — source files are moved but their content is unchanged (only #import paths updated).

Checklist

Overview

  • I have filled out all REQUIRED sections above
  • PR does one thing
  • Any Public API changes are explained in the PR details and conform to existing APIs

Testing

  • I have included test coverage for these changes, or explained why they are not needed
  • All automated tests pass, or I explained why that is not possible
  • I have personally tested this on my device, or explained why that is not possible

Final pass

  • Code is as readable as possible.
  • I have reviewed this PR myself, ensuring it meets each checklist item

Made with Cursor

@fadi-george fadi-george requested a review from a team as a code owner March 30, 2026 22:23
@@ -0,0 +1,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do you need seperate a demo_spm example? is it to maintain backward compatibility?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The demo folder has:
config:
enable-swift-package-manager: false
so its to test the pods install flow

Migrate iOS plugin source files from ios/Classes/ to the SPM-compatible
directory structure at ios/onesignal_flutter/Sources/onesignal_flutter/.
Add Package.swift targeting OneSignal-iOS-SDK 5.5.0 via SPM. Update
podspec paths so CocoaPods continues to work alongside SPM. Scaffold
demo_spm example app for SPM build verification.

Made-with: Cursor
@fadi-george fadi-george force-pushed the fadi/sdk-3401-feedback-add-flutter-swift-package-manager-support branch from 6a6917f to e2fe35c Compare April 1, 2026 17:15
and set examples/demo to not use spm
Git doesn't follow symlinked .gitignore files, so replace with a real
copy. Add missing flutter_dotenv dependency and .env asset needed by
the shared main.dart.

Made-with: Cursor
@fadi-george fadi-george force-pushed the fadi/sdk-3401-feedback-add-flutter-swift-package-manager-support branch from 691cd80 to c0b631d Compare April 1, 2026 18:13
.library(name: "onesignal-flutter", targets: ["onesignal_flutter"])
],
dependencies: [
.package(url: "https://github.com/OneSignal/OneSignal-iOS-SDK", exact: "5.5.0"),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about using https://github.com/OneSignal/OneSignal-XCFramework? I know for native iOS we recommend people to use that repository when using SPM rather than https://github.com/OneSignal/OneSignal-XCFramework for size

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@fadi-george fadi-george merged commit 36effd0 into main Apr 1, 2026
5 checks passed
@fadi-george fadi-george deleted the fadi/sdk-3401-feedback-add-flutter-swift-package-manager-support branch April 1, 2026 20:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants