Skip to content

feat(ios): add Swift Package Manager support#387

Open
TeddyYeung wants to merge 1 commit into
Dev-hwang:masterfrom
TeddyYeung:feat/add-spm-support
Open

feat(ios): add Swift Package Manager support#387
TeddyYeung wants to merge 1 commit into
Dev-hwang:masterfrom
TeddyYeung:feat/add-spm-support

Conversation

@TeddyYeung

Copy link
Copy Markdown

Why

Flutter 3.44+ makes Swift Package Manager (SPM) the default for iOS builds. CocoaPods trunk will be read-only from December 2, 2026. Plugins without SPM support will require users to pass --disable-swift-package-manager on every build.

This PR adds iOS SPM support to flutter_foreground_task so it works seamlessly with modern Flutter toolchains.

What changed

  • Added ios/flutter_foreground_task/Package.swift — SPM manifest (swift-tools-version 5.9, iOS 12.0 minimum)
  • Added ios/flutter_foreground_task/Sources/flutter_foreground_task/ — Swift-only SPM target (mirrors Classes/ Swift files, with explicit import Flutter / import UserNotifications added to files that relied on CocoaPods umbrella header auto-imports)
  • Updated ios/flutter_foreground_task.podspec — iOS platform 8.0 → 12.0
  • Updated pubspec.yaml — iOS pluginClass: SwiftFlutterForegroundTaskPlugin (direct Swift registration for SPM)
  • Updated CHANGELOG.md — 9.2.3 entry
  • Updated .gitignore — added .build/ and .swiftpm/

Architecture note

SPM does not support mixed-language targets (ObjC + Swift in the same target). The solution:

  • SPM target: Swift files only (Sources/flutter_foreground_task/)
  • CocoaPods: uses existing ios/Classes/ with ObjC wrapper + Swift implementation (unchanged)

Import fixes in SPM copies

Files in ios/Classes/ rely on the ObjC umbrella header to transitively import Flutter and UserNotifications. In the SPM target these frameworks are not auto-imported, so two files were updated with explicit imports:

  • service/ForegroundTask.swift — added import Flutter
  • service/ForegroundTaskLifecycleListeners.swift — added import Flutter
  • service/NotificationPermissionManager.swift — added import UserNotifications

Testing

  • flutter build ios --no-codesign (SPM enabled via flutter config --enable-swift-package-manager) — Build succeeded
  • flutter build ios --no-codesign (SPM disabled) — Build succeeded

Tested with Flutter 3.35.7 on macOS.

Breaking Changes

None. CocoaPods behavior is unchanged.

References

@TeddyYeung TeddyYeung force-pushed the feat/add-spm-support branch from fe42a3f to 33aa919 Compare June 26, 2026 08:53
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.

1 participant