Skip to content

feat: add Swift Package Manager support for iOS#674

Open
bbbshah wants to merge 1 commit into
fluttercommunity:mainfrom
bbbshah:feat/spm-ios-support
Open

feat: add Swift Package Manager support for iOS#674
bbbshah wants to merge 1 commit into
fluttercommunity:mainfrom
bbbshah:feat/spm-ios-support

Conversation

@bbbshah

@bbbshah bbbshah commented Jun 12, 2026

Copy link
Copy Markdown

Summary

Adds working Swift Package Manager (SPM) support for workmanager_apple while 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, a Sources/ layout, and a CI matrix), but SPM did not actually work: Flutter's tooling only detects a plugin's Swift package at ios/<plugin_name>/Package.swift, whereas it lived at ios/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

  • Move Package.swiftios/workmanager_apple/Package.swift so Flutter detects the Swift package.
  • Rename the library product workmanager_appleworkmanager-apple (Flutter requires SwiftPM product names without underscores).
  • Move PrivacyInfo.xcprivacy into the SPM target and reference it with .process("PrivacyInfo.xcprivacy") so the resource path stays inside the target root (the documented, valid form).
  • Update workmanager_apple.podspec source_files/resource_bundles paths to the new location so CocoaPods keeps building, and fix the placeholder metadata (homepage/summary/author).
  • Add import UIKit to Extensions.swift — required under SPM's per-file modular compilation for UIBackgroundFetchResult (masked under CocoaPods' single-module build).
  • Point Pigeon's swiftOut at the relocated sources.
  • Ignore .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.yml matrix now genuinely exercises SPM for the first time):

# SPM
flutter config --enable-swift-package-manager
cd example && flutter clean && flutter build ios --debug --no-codesign
# -> "All plugins found for ios are Swift Packages" -> Built Runner.app

# CocoaPods
flutter config --no-enable-swift-package-manager
cd example && flutter clean && flutter build ios --debug --no-codesign
# -> "Running pod install" -> Built Runner.app

flutter test for workmanager_apple passes; Package.swift manifest validates via swift 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 UIKit import). Those changes are reproduced here with credit (Co-Authored-By).

This PR additionally closes the remaining gaps so that both dependency managers work:

  1. Fixes the podspec paths. fix(workmanager_apple): Correct SPM structure and product name for Flutter compatibility #657 doesn't update the podspec, so after the move its globs match nothing and the CocoaPods build breaks. This PR updates them.
  2. Places the privacy resource inside the SPM target instead of .process("../../Resources"), which still escapes the target root.
  3. Adds the SPM .gitignore entries 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

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>
@docs-page

docs-page Bot commented Jun 12, 2026

Copy link
Copy Markdown

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.

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