feat(flutter_inapp_purchase): add Swift Package Manager support for iOS and macOS#161
feat(flutter_inapp_purchase): add Swift Package Manager support for iOS and macOS#161alihassan143 wants to merge 6 commits into
Conversation
…OS and macOS - Rewrite Package.swift with proper iOS 15.0 and macOS 14.0 platform declarations, removing incorrect ObjC-only publicHeadersPath and cSettings - Add OpenIAP SPM dependency (https://github.com/hyodotdev/openiap.git v2.2.1) so the plugin's native OpenIAP import resolves correctly under SPM - Point the SPM target to ios/Classes which already uses #if canImport(FlutterMacOS) conditionals, making a single source tree compile correctly for both platforms - Sync macos/Classes/FlutterInappPurchasePlugin.swift with the canonical iOS version, restoring feature parity for CocoaPods macOS builds (beginRefundRequestIOS, syncIOS, subscriptionStatusIOS, currentEntitlementIOS, latestTransactionIOS, isTransactionVerifiedIOS, getTransactionJwsIOS, getReceiptDataIOS, getAppTransactionIOS, verifyPurchaseWithProvider and proper availability guards)
📝 WalkthroughWalkthroughFlutter in-app purchase library restructures its build system to adopt a Swift Package Manager-first architecture. Platform minimums increase to iOS 15.0 and macOS 14.0. The OpenIAP dependency (2.2.1) is integrated at the root Package.swift level. Source file locations move to ChangesSwiftPM Migration & Example Project Configuration
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related issues
Possibly related PRs
Suggested labels
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
libraries/flutter_inapp_purchase/Package.swift (1)
14-18: 💤 Low valueConsider using a less restrictive version constraint for the OpenIAP dependency.
Using
exact: "2.2.1"prevents downstream consumers from automatically receiving security patches (e.g., 2.2.2). If strict reproducibility isn't required, consider.upToNextPatch(from: "2.2.1")to allow patch-level updates while maintaining API compatibility.💡 Suggested alternative
dependencies: [ .package( url: "https://github.com/hyodotdev/openiap.git", - exact: "2.2.1" + .upToNextPatch(from: "2.2.1") ), ],🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@libraries/flutter_inapp_purchase/Package.swift` around lines 14 - 18, Change the OpenIAP dependency declaration in Package.swift to allow patch upgrades instead of pinning to an exact version: locate the .package entry that currently uses exact: "2.2.1" for the "https://github.com/hyodotdev/openiap.git" dependency and replace the version constraint with .upToNextPatch(from: "2.2.1") so downstream consumers can receive patch security fixes while preserving API compatibility.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@libraries/flutter_inapp_purchase/Package.swift`:
- Around line 14-18: Change the OpenIAP dependency declaration in Package.swift
to allow patch upgrades instead of pinning to an exact version: locate the
.package entry that currently uses exact: "2.2.1" for the
"https://github.com/hyodotdev/openiap.git" dependency and replace the version
constraint with .upToNextPatch(from: "2.2.1") so downstream consumers can
receive patch security fixes while preserving API compatibility.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 2d9560cd-b0f0-44b5-9c14-a663cde81efc
📒 Files selected for processing (2)
libraries/flutter_inapp_purchase/Package.swiftlibraries/flutter_inapp_purchase/macos/Classes/FlutterInappPurchasePlugin.swift
There was a problem hiding this comment.
Code Review
This pull request updates the flutter_inapp_purchase package to support macOS (14.0+) and increases the minimum iOS version to 15.0. It integrates the OpenIAP dependency and introduces several new StoreKit 2 and external purchase functionalities, including refund requests, entitlement queries, transaction verification, and subscription status. Feedback was provided regarding a potential mismatch in the package name for the OpenIAP dependency in the Swift package manifest.
| resources: [ | ||
| .process("../Assets") | ||
| dependencies: [ | ||
| .product(name: "OpenIAP", package: "openiap"), |
There was a problem hiding this comment.
The package name for the OpenIAP dependency should likely be 'OpenIAP' (matching the product name) rather than 'openiap'. Please verify the package name defined in the dependency's Package.swift.
| .product(name: "OpenIAP", package: "openiap"), | |
| .product(name: "OpenIAP", package: "OpenIAP"), |
hyochan
left a comment
There was a problem hiding this comment.
Thanks for taking this on. I don't think this is ready to merge in its current form.
The OpenIAP product dependency line looks okay as written: SwiftPM resolves the URL dependency with identity openiap, and I verified swift package resolve succeeds with .product(name: "OpenIAP", package: "openiap"). So I would not apply the suggested change to package: "OpenIAP" unless Xcode/Flutter tooling proves otherwise.
The larger issue is that this does not add Flutter plugin SPM support in the layout Flutter expects. Flutter's plugin-author guide expects the manifest under the platform plugin directory, for example ios/flutter_inapp_purchase/Package.swift and/or macos/flutter_inapp_purchase/Package.swift, with sources under Sources/flutter_inapp_purchase. The Swift files also need to be moved or mirrored there, and the podspec source paths need to be updated accordingly so CocoaPods continues to work.
This manifest also removes the Flutter dependency surface rather than replacing it with the SPM equivalent. On Flutter 3.41+, the plugin manifest should include the FlutterFramework package dependency documented by Flutter; otherwise the target imports Flutter but the package has no dependency that provides it. I hit that locally:
swift build
...
error: no such module 'Flutter'
A few concrete fixes I would expect before this lands:
- Add platform-specific SPM manifests in the Flutter-supported locations instead of only changing the repository-root plugin
Package.swift. - Move/mirror
ios/Classesinto the correspondingSources/flutter_inapp_purchasedirectory and update the iOS/macOS podspecs to keep CocoaPods working. - Add the Flutter 3.41
FlutterFrameworkdependency in the SPM target. - Keep the library product name hyphenated (
flutter-inapp-purchase) per Flutter's guidance for plugin names containing underscores. - Re-verify with a Flutter example build with Swift Package Manager enabled for both iOS and macOS, not just
swift package resolve.
References:
Restructure iOS and macOS Swift sources into SPM-compatible layout under flutter_inapp_purchase/Sources/flutter_inapp_purchase/. Add Package.swift manifests for both platforms, update podspecs to point to the new source paths, and wire up Xcode projects in the example app to use FlutterGeneratedPluginSwiftPackage. Fix missing env asset that blocked macOS and iOS example builds.
|
@hyochan now PR ready for review |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@libraries/flutter_inapp_purchase/Package.swift`:
- Around line 17-25: The root Package.swift target "flutter_inapp_purchase" is
missing the FlutterFramework dependency required by sources that import
Flutter/FlutterMacOS (see FlutterInappPurchasePlugin.swift); either remove the
root Package.swift if it's unused to avoid divergence, or add the
FlutterFramework package+product to the target's dependencies (mirror what the
platform-specific Package.swift files do) so the target resolves imports of
Flutter/FlutterMacOS.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 808073e1-0fb6-40bf-8be7-23e1bc2e613b
📒 Files selected for processing (20)
libraries/flutter_inapp_purchase/Package.swiftlibraries/flutter_inapp_purchase/example/.gitignorelibraries/flutter_inapp_purchase/example/ios/Runner.xcodeproj/project.pbxprojlibraries/flutter_inapp_purchase/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcschemelibraries/flutter_inapp_purchase/example/ios/Runner/AppDelegate.hlibraries/flutter_inapp_purchase/example/ios/Runner/AppDelegate.mlibraries/flutter_inapp_purchase/example/ios/Runner/Info.plistlibraries/flutter_inapp_purchase/example/macos/Runner.xcodeproj/project.pbxprojlibraries/flutter_inapp_purchase/example/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcschemelibraries/flutter_inapp_purchase/ios/Assets/.gitkeeplibraries/flutter_inapp_purchase/ios/flutter_inapp_purchase.podspeclibraries/flutter_inapp_purchase/ios/flutter_inapp_purchase/Package.swiftlibraries/flutter_inapp_purchase/ios/flutter_inapp_purchase/Sources/flutter_inapp_purchase/FlutterIapHelper.swiftlibraries/flutter_inapp_purchase/ios/flutter_inapp_purchase/Sources/flutter_inapp_purchase/FlutterIapLog.swiftlibraries/flutter_inapp_purchase/ios/flutter_inapp_purchase/Sources/flutter_inapp_purchase/FlutterInappPurchasePlugin.swiftlibraries/flutter_inapp_purchase/macos/flutter_inapp_purchase.podspeclibraries/flutter_inapp_purchase/macos/flutter_inapp_purchase/Package.swiftlibraries/flutter_inapp_purchase/macos/flutter_inapp_purchase/Sources/flutter_inapp_purchase/FlutterIapHelper.swiftlibraries/flutter_inapp_purchase/macos/flutter_inapp_purchase/Sources/flutter_inapp_purchase/FlutterIapLog.swiftlibraries/flutter_inapp_purchase/macos/flutter_inapp_purchase/Sources/flutter_inapp_purchase/FlutterInappPurchasePlugin.swift
✅ Files skipped from review due to trivial changes (3)
- libraries/flutter_inapp_purchase/example/ios/Runner/AppDelegate.h
- libraries/flutter_inapp_purchase/example/.gitignore
- libraries/flutter_inapp_purchase/macos/flutter_inapp_purchase/Package.swift
| targets: [ | ||
| .target( | ||
| name: "flutter_inapp_purchase", | ||
| dependencies: [], | ||
| path: "ios/Classes", | ||
| resources: [ | ||
| .process("../Assets") | ||
| dependencies: [ | ||
| .product(name: "OpenIAP", package: "openiap"), | ||
| ], | ||
| publicHeadersPath: "", | ||
| cSettings: [ | ||
| .headerSearchPath("../Flutter"), | ||
| .headerSearchPath("../../../Flutter/Export") | ||
| ] | ||
| path: "ios/flutter_inapp_purchase/Sources/flutter_inapp_purchase" | ||
| ) | ||
| ] |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# Locate all Package.swift manifests for this plugin and inspect their dependencies/paths.
fd -t f 'Package.swift' libraries/flutter_inapp_purchase --exec sh -c 'echo "==== {} ===="; cat "{}"'
# Confirm the target sources actually import Flutter modules.
rg -nP 'import\s+(Flutter|FlutterMacOS)|canImport\(FlutterMacOS\)' libraries/flutter_inapp_purchase/ios/flutter_inapp_purchase/Sources -C1Repository: hyodotdev/openiap
Length of output: 4563
Root Package.swift is missing FlutterFramework dependency for sources that import Flutter/FlutterMacOS
The root libraries/flutter_inapp_purchase/Package.swift target depends only on OpenIAP:
targets: [
.target(
name: "flutter_inapp_purchase",
dependencies: [
.product(name: "OpenIAP", package: "openiap"),
],
path: "ios/flutter_inapp_purchase/Sources/flutter_inapp_purchase"
)
]…but the corresponding sources libraries/flutter_inapp_purchase/ios/flutter_inapp_purchase/Sources/flutter_inapp_purchase/FlutterInappPurchasePlugin.swift contain import FlutterMacOS / import Flutter. The platform-specific manifests in libraries/flutter_inapp_purchase/ios/flutter_inapp_purchase/Package.swift and libraries/flutter_inapp_purchase/macos/flutter_inapp_purchase/Package.swift add the needed FlutterFramework dependency, while the root manifest does not.
If the root manifest is no longer used, remove it to avoid divergence; otherwise add FlutterFramework (package + product) to the root target so it can resolve Flutter/FlutterMacOS.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@libraries/flutter_inapp_purchase/Package.swift` around lines 17 - 25, The
root Package.swift target "flutter_inapp_purchase" is missing the
FlutterFramework dependency required by sources that import Flutter/FlutterMacOS
(see FlutterInappPurchasePlugin.swift); either remove the root Package.swift if
it's unused to avoid divergence, or add the FlutterFramework package+product to
the target's dependencies (mirror what the platform-specific Package.swift files
do) so the target resolves imports of Flutter/FlutterMacOS.
#160
Summary by CodeRabbit
New Features
Chores