diff --git a/CHANGELOG.md b/CHANGELOG.md index b48d31e1..958fcf0f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,9 +2,10 @@ All notable changes to this project will be documented in this file. -## [0.11.1](https://github.com/bizz84/SwiftyStoreKit/releases/tag/0.11.1) Add `transactionDate` to `PaymentTransaction` +## [0.11.1](https://github.com/bizz84/SwiftyStoreKit/releases/tag/0.11.1) Add `PaymentTransaction.transactionDate` and `SKProduct.localizedIntroductoryPrice` * Add `transactionDate` to `PaymentTransaction` ([#316](https://github.com/bizz84/SwiftyStoreKit/pull/316), see [#312](https://github.com/bizz84/SwiftyStoreKit/issues/312)). +* Add `localizedIntroductoryPrice` to `SKProduct` ([#318](https://github.com/bizz84/SwiftyStoreKit/pull/318)). ## [0.11.0](https://github.com/bizz84/SwiftyStoreKit/releases/tag/0.11.0) Add `fetchReceipt` method + update `verifyReceipt` and `ReceiptValidator` protocol diff --git a/SwiftyStoreKit/SKProduct+LocalizedPrice.swift b/SwiftyStoreKit/SKProduct+LocalizedPrice.swift index 04106e17..41778074 100644 --- a/SwiftyStoreKit/SKProduct+LocalizedPrice.swift +++ b/SwiftyStoreKit/SKProduct+LocalizedPrice.swift @@ -28,9 +28,21 @@ import StoreKit public extension SKProduct { public var localizedPrice: String? { + return formattedPrice(price: price, locale: priceLocale) + } + + @available(iOS 11.2, OSX 10.13.2, tvOS 11.2, *) + public var localizedIntroductoryPrice: String? { + guard let introductoryPrice = introductoryPrice else { + return nil + } + return formattedPrice(price: introductoryPrice.price, locale: introductoryPrice.priceLocale) + } + + private func formattedPrice(price: NSDecimalNumber, locale: Locale) -> String? { let numberFormatter = NumberFormatter() - numberFormatter.locale = self.priceLocale + numberFormatter.locale = locale numberFormatter.numberStyle = .currency - return numberFormatter.string(from: self.price) + return numberFormatter.string(from: price) } }