feat: add Swift Package Manager support for iOS#674
Open
bbbshah wants to merge 1 commit into
Open
Conversation
Relocate the workmanager_apple iOS plugin into the directory layout that
Flutter's Swift Package Manager (SPM) integration detects, while keeping
full CocoaPods backward compatibility. Plugins are expected to support both
dependency managers during the transition.
- Move Package.swift to ios/workmanager_apple/Package.swift so Flutter
detects the Swift package (previously at ios/Package.swift, never found).
- Rename the library product to "workmanager-apple" (Flutter requires SwiftPM
product names without underscores).
- Move the privacy manifest into the SPM target and reference it with
.process("PrivacyInfo.xcprivacy") so the resource path stays inside the
target root.
- Update workmanager_apple.podspec source_files/resource_bundles paths to the
new location so CocoaPods builds keep working, and fix placeholder metadata.
- Add import UIKit to Extensions.swift (required under SPM's per-file modular
compilation for UIBackgroundFetchResult).
- Point the Pigeon swiftOut path at the relocated sources.
- Ignore .build/ and .swiftpm/.
Verified the example app builds under both SPM
(flutter config --enable-swift-package-manager) and CocoaPods.
Co-Authored-By: Iwan Gerber <info@ih-app.de>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
To view this pull requests documentation preview, visit the following URL: docs.page/fluttercommunity/flutter_workmanager~674 Documentation is deployed and generated using docs.page. |
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.
Summary
Adds working Swift Package Manager (SPM) support for
workmanager_applewhile keeping full CocoaPods backward compatibility. Per Flutter's guidance, plugins should support both dependency managers during the transition (CocoaPods registry goes read-only Dec 2, 2026).The package already had partial SPM scaffolding (
Package.swift, aSources/layout, and a CI matrix), but SPM did not actually work: Flutter's tooling only detects a plugin's Swift package atios/<plugin_name>/Package.swift, whereas it lived atios/Package.swift, so Flutter silently fell back to CocoaPods. The privacy-manifest resource path also pointed outside the SPM target root, which SPM rejects.Changes
Package.swift→ios/workmanager_apple/Package.swiftso Flutter detects the Swift package.workmanager_apple→workmanager-apple(Flutter requires SwiftPM product names without underscores).PrivacyInfo.xcprivacyinto the SPM target and reference it with.process("PrivacyInfo.xcprivacy")so the resource path stays inside the target root (the documented, valid form).workmanager_apple.podspecsource_files/resource_bundlespaths to the new location so CocoaPods keeps building, and fix the placeholder metadata (homepage/summary/author).import UIKittoExtensions.swift— required under SPM's per-file modular compilation forUIBackgroundFetchResult(masked under CocoaPods' single-module build).swiftOutat the relocated sources..build/and.swiftpm/.No minimum-Flutter bump is required: SPM works from Flutter 3.24+ without declaring a Flutter package dependency, so the existing
flutter: ">=3.32.0"constraint is unchanged.Testing
Verified the example app builds under both dependency managers (the existing
examples.ymlmatrix now genuinely exercises SPM for the first time):flutter testforworkmanager_applepasses;Package.swiftmanifest validates viaswift package dump-package.Relationship to #657
This builds on the work in #657 by @IwO30, which correctly identified the same root cause and fixed the structural essentials (Package.swift location, hyphen product name, and the
UIKitimport). Those changes are reproduced here with credit (Co-Authored-By).This PR additionally closes the remaining gaps so that both dependency managers work:
.process("../../Resources"), which still escapes the target root..gitignoreentries and cleans up placeholder podspec metadata.If the maintainers would prefer to merge #657 first, this PR cleanly reduces to the podspec/resource/gitignore deltas. Happy to coordinate either way.
Out of scope
macOS support. The core plugin uses iOS-only APIs (
BackgroundTasks/UIKit), so macOS would require real implementation work beyond packaging; this PR keeps parity with the existing iOS-only plugin.🤖 Generated with Claude Code