feat(ios): add Swift Package Manager support#387
Open
TeddyYeung wants to merge 1 commit into
Open
Conversation
fe42a3f to
33aa919
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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-manageron every build.This PR adds iOS SPM support to
flutter_foreground_taskso it works seamlessly with modern Flutter toolchains.What changed
ios/flutter_foreground_task/Package.swift— SPM manifest (swift-tools-version 5.9, iOS 12.0 minimum)ios/flutter_foreground_task/Sources/flutter_foreground_task/— Swift-only SPM target (mirrors Classes/ Swift files, with explicitimport Flutter/import UserNotificationsadded to files that relied on CocoaPods umbrella header auto-imports)ios/flutter_foreground_task.podspec— iOS platform 8.0 → 12.0pubspec.yaml— iOS pluginClass: SwiftFlutterForegroundTaskPlugin (direct Swift registration for SPM)CHANGELOG.md— 9.2.3 entry.gitignore— added.build/and.swiftpm/Architecture note
SPM does not support mixed-language targets (ObjC + Swift in the same target). The solution:
Sources/flutter_foreground_task/)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 importFlutterandUserNotifications. In the SPM target these frameworks are not auto-imported, so two files were updated with explicit imports:service/ForegroundTask.swift— addedimport Flutterservice/ForegroundTaskLifecycleListeners.swift— addedimport Flutterservice/NotificationPermissionManager.swift— addedimport UserNotificationsTesting
flutter build ios --no-codesign(SPM enabled viaflutter config --enable-swift-package-manager) — Build succeededflutter build ios --no-codesign(SPM disabled) — Build succeededTested with Flutter 3.35.7 on macOS.
Breaking Changes
None. CocoaPods behavior is unchanged.
References