iPhone - 如何检索应用内购买的自动续订订阅的持续时间

发布于 2024-10-20 16:00:25 字数 352 浏览 3 评论 0原文

我正在考虑为 iPhone 应用程序设置应用内购买。 我计划使用新的自动续订订阅类型。但是,我想为特定订阅提供多个持续时间,但无法了解如何从 SKProductsResponse.products 数组中返回的 SKProduct 检索持续时间。

SKProduct 对象具有价格、localizedTitle 和 localizedDescription。但是,如果您设置具有多个持续时间的订阅系列,则该系列的标题/描述会设置一次,因此您无法包含持续时间,并且文档明确表示不要在标题/描述中包含持续时间。但是,看不到任何其他字段,我可以在其中检索在应用商店中的自定义中显示的持续时间。要么是我遗漏了某些东西,要么是 4.3 之前它才可用?

非常感谢指点!

I'm looking at setting up In App Purchases for an iPhone app.
I'm planning on using the new auto-renewable subscription type. However, I want to offer multiple durations for a particular subscription, but can't see how I can retrieve the duration from the SKProduct that is returned in the SKProductsResponse.products array.

The SKProduct object has price, localizedTitle and localizedDescription. However, if you set up a subscription family with multiple durations the title/description are set once for the family so you cannot include the duration, and the docs explicitly say don't include the duration in the title/description. However, can't see any other field where I can retrieve the duration for displaying in my custom in app store. Either I'm missing something or it isn't going to be available until 4.3?

Pointers greatly appreciated!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

吾性傲以野 2024-10-27 16:00:25

您需要有一些映射 product_id =>; length 某处,无论是在您的应用程序中还是从应用程序的后端检索。

You need to have some mapping product_id => length somewhere, either in your app or retrived from your app's backend.

水溶 2024-10-27 16:00:25

您可以为每个持续时间使用特定的产品标识符(在下面的代码中,1 个月订阅的产品标识符为“com.domainname.myapp.sub1month”,7 天持续时间的产品标识符为“com.domainname.myapp.sub7day”)并且在 paymentQueue 中搜索:

-(void) paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions{
   for(SKPaymentTransaction *transaction in transactions){
     switch (transaction.transactionState){
        case SKPaymentTransactionStatePurchasing:
            break;
        case SKPaymentTransactionStatePurchased:
            if([transaction.payment.productIdentifier isEqualToString:@"com.domainname.myapp.sub1month"]{
                newSubscriptionEndDate=[transaction.transactionDate timeIntervalSinceReferenceDate]+3600*24*31;
            }
            if([transaction.payment.productIdentifier isEqualToString:@"com.domainname.myapp.sub7day"]  ){
                newSubscriptionEndDate=[transaction.transactionDate timeIntervalSinceReferenceDate]+3600*24*7;
            }
            [[SKPaymentQueue defaultQueue] finishTransaction: transaction];
            break;

You can use a specific productIdentifier for each duration (in the code below the productIdentifier for a 1 month subscription is "com.domainname.myapp.sub1month" and for a 7 day duration it is "com.domainname.myapp.sub7day") and search for that in the paymentQueue:

-(void) paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions{
   for(SKPaymentTransaction *transaction in transactions){
     switch (transaction.transactionState){
        case SKPaymentTransactionStatePurchasing:
            break;
        case SKPaymentTransactionStatePurchased:
            if([transaction.payment.productIdentifier isEqualToString:@"com.domainname.myapp.sub1month"]{
                newSubscriptionEndDate=[transaction.transactionDate timeIntervalSinceReferenceDate]+3600*24*31;
            }
            if([transaction.payment.productIdentifier isEqualToString:@"com.domainname.myapp.sub7day"]  ){
                newSubscriptionEndDate=[transaction.transactionDate timeIntervalSinceReferenceDate]+3600*24*7;
            }
            [[SKPaymentQueue defaultQueue] finishTransaction: transaction];
            break;
策马西风 2024-10-27 16:00:25

iOS 11.2 将 subscriptionDuration 属性引入 SKProduct。不过,我认为旧版 iOS 没有退路。

https://developer.apple.com/documentation/storekit/skproduct/2936884-subscriptionperiod

iOS 11.2 brings the subscriptionDuration property to SKProduct. I don't think there is a fallback for older iOS though.

https://developer.apple.com/documentation/storekit/skproduct/2936884-subscriptionperiod

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文