英文:
How to show the monthly price of a yearly subscription in StoreKit 2?
问题
I can show the total yearly (or 6-month) auto renewable subscription price using displayPrice just fine, but I also want to show how much that would be per month, as I think it's more enticing.
我可以很好地显示总年度(或6个月)自动可续订订阅价格,只是我也想显示每月多少,因为我认为这更具吸引力。
I could just use price and divide by 12 (or 6), but then I wouldn't know how to show the local currency symbol next to the price.
我可以简单地使用price并除以12(或6),但然后我就不知道如何在价格旁边显示本地货币符号。
According to my googling this is easy to do in StoreKit 1 using SKProduct
, but how do I do it in StoreKit 2 using Product
?
根据我的搜索结果,在StoreKit 1中使用SKProduct
很容易实现这一点,但在StoreKit 2中使用Product
应该如何做呢?
Thanks!
谢谢!
PD: Is there a way to be able to test the different locales to make sure their prices/currency symbols are showing correctly?
附注:是否有一种方法可以测试不同的区域设置,以确保价格/货币符号显示正确?
英文:
I can show the total yearly (or 6-month) auto renewable subscription price using displayPrice just fine, but I also want to show how much that would be per month, as I think its more enticing.
I could just use price and divide by 12 (or 6), but then I wouldn't know how to show the local currency symbol next to the price.
According to my googling this is easy to do in StoreKit 1 using SKProduct
, but how do I do it in StoreKit 2 using Product
?
Thanks!
PD: Is there a way to be able to test the different locales to make sure their prices/currency symbols are showing correctly?
答案1
得分: 1
是的,priceLocale
在 StoreKit 2 中不可用确实令人困扰。显然,在 StoreKit 2 中移除了 priceLocale
,因为它并不经常被使用!
要显示每月价格 - 你是正确的 - 你只需使用 price
,然后除以 12 或 6。这就是在他们的文档中所说的:
> 使用此属性对产品的价格执行算术计算。要向客户显示价格的本地化字符串表示形式,请改用 displayPrice
属性。
要知道在价格旁边显示本地货币符号,你将不得不依赖于 priceFormatStyle
然后提取 currency。
至于测试,我唯一做的就是创建多个带有不同区域的沙盒测试人员,以查看以其所在地区显示的价格。
但要知道 - 如果你只是使用 displayPrice
- 你无需担心任何事情。价格将始终以该应用商店的区域设置显示。这些复杂性出现是因为你想对价格执行操作(在这里 - 将其转换为每月价格),然后显示它。
英文:
Yeah, it is annoying that priceLocale
is not available on the SKProduct object in StoreKit 2. Apparently priceLocale
was removed in StoreKit 2 because it was not used very often!
To show your monthly price - you are correct - you will have to just use price
and divide by 12 or 6. That's what they say in their docs:
> Use this property to perform arithmetic calculations with the price of
> the product. For a localized string representation of the price to
> display to customers, use the displayPrice
property instead.
To know what to show the as local currency symbol next to the price, you will have to rely on priceFormatStyle
and then extract the currency
As for testing, the only thing I do is to have multiple sandbox testers created with different regions to see the prices displayed in their locale.
But know this - if you are using just displayPrice
- you have to worry about nothing. The price will always be in the locale of that App Store. These complications come in because you want to perform operations on your price (here - translating it to monthly) and then show it.
答案2
得分: -1
这将类似于以下内容:
let monthlyPriceDecimal = productItem.price.doubleValue / 12
self.lblYearly.text = "\(productItem.priceLocale.currencySymbol ?? "") \(String(format: "%.2f", monthlyPriceDecimal)) / 月"
英文:
It will be something like this,
let monthlyPriceDecimal = productItem.price.doubleValue/12
self.lblYearly.text = "\(productItem.priceLocale.currencySymbol ?? "") \(String(format: "%.2f", monthlyPriceDecimal)) / Month"
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论