Skip to content
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

Merged
merged 1 commit into from
May 5, 2024

Conversation

Hengyu
Copy link
Contributor

@Hengyu Hengyu commented May 5, 2024

We can use Product.SubscriptionPeriod's formatted method to display price.

https://developer.apple.com/documentation/storekit/product/subscriptionperiod/4044346-formatted

This PR also simplifies code structure/

}

/// The price text for display (e.g. "$0.99 / 1 month", "$1.99 / 2 months").
public var displayPrice: String {
Copy link
Contributor Author

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.

Copy link
Owner

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 {
Copy link
Contributor Author

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

Copy link
Owner

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
Copy link
Contributor Author

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

@Hengyu
Copy link
Contributor Author

Hengyu commented May 5, 2024

@russell-archer PTAL

@russell-archer
Copy link
Owner

Really excellent PR! Thank you Hengyu!

@russell-archer russell-archer merged commit 2e73d0b into russell-archer:main May 5, 2024
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.

None yet

2 participants