-
Notifications
You must be signed in to change notification settings - Fork 47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use system format for subscription price display #78
Conversation
} | ||
|
||
/// The price text for display (e.g. "$0.99 / 1 month", "$1.99 / 2 months"). | ||
public var displayPrice: String { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use Apple's recommended API for price display. The API can handle localization as well as singluar and plural units.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very good idea. This wasn't available when I first wrote the code so I had to create my display logic. Much better to use Apple's that supports proper localization.
@@ -56,21 +85,18 @@ public struct PrePurchaseSubscriptionInfo: Hashable { | |||
/// single element with the promo id (which will be nil) and price/period for the offer. | |||
/// - If there are no offers, the value of this property will be an array with a single element with the standard price/period. | |||
public var purchasePriceForDisplay: [PurchasePriceForDisplay]? { | |||
if promotionalOffersEligible, let promotionalOffers, promotionalOffers.count > 0 { | |||
if promotionalOffersEligible, !promotionalOffers.isEmpty { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using isEmpty
is better than using count
to tell if an array has elements
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I checked and yes you're correct! Apple recommend using isEmpty!
case .payUpFront: return "Pay up front" | ||
default: return "Unknown" | ||
if #available(iOS 15.4, macOS 12.3, tvOS 15.4, watchOS 8.5, visionOS 1.0, *) { | ||
mode.localizedDescription |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use Apple's API to support for localization
@russell-archer PTAL |
Really excellent PR! Thank you Hengyu! |
We can use
Product.SubscriptionPeriod
'sformatted
method to display price.https://developer.apple.com/documentation/storekit/product/subscriptionperiod/4044346-formatted
This PR also simplifies code structure/