14

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

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

指点非常感谢!

4

3 回答 3

11

您需要在product_id => length某个地方进行一些映射,无论是在您的应用程序中还是从应用程序的后端检索。

于 2011-03-27T09:21:18.760 回答
9

您可以为每个持续时间使用特定的 productIdentifier(在 productIdentifier 下面的代码中,订阅 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;
于 2011-03-30T18:34:24.457 回答
6

iOS 11.2 将该subscriptionDuration属性带到SKProduct. 不过,我认为旧版 iOS 没有退路。

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

于 2018-03-01T18:08:30.100 回答