【问题标题】:Purchasing multiple consumables at a time一次购买多个消耗品
【发布时间】:2016-12-13 12:49:58
【问题描述】:

我允许用户一次购买多个(相同类型的)消耗品。我已经实现了以下代码:

- (void)purchaseMyProduct:(NSArray *) products {
     if ([SKPaymentQueue canMakePayments]) {        
         for(SKProduct *product in products) {
            SKPayment *payment = [SKPayment paymentWithProduct:product];
           [[SKPaymentQueue defaultQueue] addPayment:payment];
        }

         [[SKPaymentQueue defaultQueue] addTransactionObserver:self];   
     }
   else {
      UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:
                              @"Purchases are disabled in your device" message:nil delegate:
                              self cancelButtonTitle:@"Ok" otherButtonTitles: nil];
    [alertView show];
}

}

-(void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions {
UIAlertView *alertView ;
for (SKPaymentTransaction *transaction in transactions) {
    switch (transaction.transactionState) {

        case SKPaymentTransactionStatePurchasing:
            NSLog(@"Purchasing");
            break;

        case SKPaymentTransactionStatePurchased:                                 
            [[SKPaymentQueue defaultQueue] finishTransaction:transaction];
                [self 
            break;

        default:
            break;
    }
}

}

但问题是,对于每个单独的消耗品条目,都会显示一个单独的提示,要求用户确认购买。

是否可以在 IAP 中一次购买多个相同类型的消耗品,并为用户提供一个提示?

我认为的一个逻辑是在商店中为多种消耗品创建单独的产品,例如一个产品两个,一个产品三个消耗品。

请帮忙。

谢谢,

【问题讨论】:

    标签: ios objective-c in-app-purchase


    【解决方案1】:

    如果它们属于同一类型,则应使用数量字段。查看SKPayment 类参考。数量的最大值为 10。

    要创建数量大于 1 的 SKPayment 对象,请创建一个 SKMutablePayment 对象,调整其数量属性,然后将其添加到支付队列中。

    文档中的示例:

    SKMutablePayment *myPayment = [SKMutablePayment paymentWithProduct: myProduct];
    myPayment.quantity = 2;
    [[SKPaymentQueue defaultQueue] addPayment:myPayment];
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-10-10
      • 1970-01-01
      • 2021-07-10
      • 1970-01-01
      • 2016-01-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多