fix(apple): add iOS 15 compatibility for priceFormatStyle API#80
fix(apple): add iOS 15 compatibility for priceFormatStyle API#80
Conversation
- Add currencyCode() helper with #available check for iOS 16+ - Fall back to Locale.current.currencyCode on iOS 15 - Unify @available annotations with tvOS 16.0, watchOS 8.0 - Fix macOS version inconsistency (12.0 → 14.0) in some files - Add Apple documentation SeeAlso links to all main types This ensures StoreKit 2 works correctly on iOS 15 devices where priceFormatStyle.currencyCode could cause crashes. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add s.watchos.deployment_target = '8.0' to match Package.swift Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
|
Warning Rate limit exceeded
⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. 📝 WalkthroughWalkthroughThe PR expands Apple platform support by adding tvOS 16.0 and watchOS 8.0 availability annotations across multiple framework files, introduces a new Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested labels
Poem
🚥 Pre-merge checks | ✅ 1 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (1 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 |
Summary of ChangesHello @hyochan, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request enhances the stability and maintainability of the Apple In-App Purchase (IAP) module by introducing backward compatibility for price formatting on iOS 15, standardizing API availability declarations across multiple platforms, and improving developer experience through integrated documentation links. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request effectively addresses a potential crash on iOS 15 by introducing a compatibility helper for priceFormatStyle.currencyCode. The changes also improve code consistency by unifying @available annotations and enhance documentation with links to Apple's official resources. I've suggested one improvement to the iOS 15 fallback logic to make it more accurate by using the product's locale instead of the device's current locale, which could differ from the App Store storefront currency.
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
packages/apple/openiap.podspec (1)
19-22:⚠️ Potential issue | 🟡 MinorDescription doesn't mention watchOS.
Now that watchOS is a supported platform, consider updating the description to include it.
Proposed fix
s.description = <<-DESC - OpenIAP is a modern Swift library for handling in-app purchases using StoreKit 2. - Supports iOS, macOS, and tvOS with a simple and intuitive API. + OpenIAP is a modern Swift library for handling in-app purchases using StoreKit 2. + Supports iOS, macOS, tvOS, and watchOS with a simple and intuitive API. DESC
🧹 Nitpick comments (2)
packages/apple/Sources/Helpers/StoreKitTypesBridge.swift (1)
507-514: iOS 15 fallback returns device locale currency, not the product's currency.
Locale.current.currencyCodereturns the currency for the user's device locale, which may differ from the product's actual currency (e.g., a user with US locale buying from a JP storefront). This is a known limitation and an acceptable tradeoff for iOS 15 wherepriceFormatStyle.currencyCodeisn't available, but it would be helpful to document this caveat inline.Also,
Locale.current.currencyCodeis deprecated starting iOS 16 / macOS 13. Since this code path is only reachable on older OS versions (guarded by#available), it won't cause runtime issues, but it may trigger a compile-time deprecation warning.📝 Suggested inline documentation
static func currencyCode(from product: StoreKit.Product) -> String? { if `#available`(iOS 16.0, macOS 13.0, tvOS 16.0, watchOS 9.0, *) { return product.priceFormatStyle.currencyCode } else { - // iOS 15 fallback - use locale's currency + // iOS 15 fallback - uses device locale's currency, which may differ from the + // product's actual currency. This is the best approximation available on iOS 15 + // where priceFormatStyle.currencyCode doesn't exist. return Locale.current.currencyCode } }packages/apple/Sources/OpenIapStore.swift (1)
417-418: Pre-existing:getAppTransactionIOSavailability is narrower than its implementation.Not introduced by this PR, but worth noting:
OpenIapStore.getAppTransactionIOS()has@available(iOS 16.0, macOS 14.0, *)(missing tvOS/watchOS), while its implementation inOpenIapModule.swift(Line 827) has@available(iOS 16.0, macOS 14.0, tvOS 16.0, watchOS 9.0, *). The same gap exists inOpenIapModule+ObjC.swift(Line 606). Consider aligning these in a follow-up.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Use product.priceFormatStyle.locale.currencyCode instead of Locale.current.currencyCode to get the correct App Store currency rather than the device's locale currency. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
## Summary - Use `#if os(iOS) || os(tvOS)` instead of `canImport(UIKit)` for UIWindowScene (not available on watchOS) - Use `#if os(iOS)` for `presentCodeRedemptionSheet` (iOS-only API) - Use `#if os(iOS) || os(tvOS) || os(visionOS)` for `UIApplication.open` (not available on watchOS/macOS) - Add `watchOS 9.0` to `@available` for `getAppTransactionIOS` (AppTransaction requires watchOS 9.0+) - Add `tvOS 16.0` to `@available` annotations for consistency Fixes watchOS build errors that occurred after merging #80. ## Test plan - [x] Validated with `pod lib lint openiap.podspec --allow-warnings` - [ ] CI build passes for all platforms (iOS, macOS, tvOS, watchOS) 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Added support for tvOS 16.0 and watchOS 9.0 platforms. * **Improvements** * Enhanced platform detection logic across Apple devices for better compatibility. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
Summary
priceFormatStyle.currencyCode@availableannotations across all Swift filesChanges
StoreKit 2 iOS 15 Compatibility
currencyCode(from:)helper function with#available(iOS 16.0, ...)checkLocale.current.currencyCodeon iOS 15@available Annotation Unification
@available(iOS 15.0, macOS 14.0, tvOS 16.0, watchOS 8.0, *)12.0→14.0(matches podspec)Documentation Links
Added Apple Developer documentation
SeeAlsolinks:ProductManager→/storekit/productIapState→/storekit/transactionStoreKitTypesBridge→/storekit/productOpenIapModule→/storekit/in-app_purchaseOpenIapStore→/storekit/in-app_purchaseOpenIapProtocol→/storekit/transactionOpenIapSerialization→/storekitTest plan
swift buildpasses🤖 Generated with Claude Code
Summary by CodeRabbit
Release Notes
New Features
Documentation
Refactor