一次购买多个消耗品 [英] Purchasing multiple consumables at a time

查看:298
本文介绍了一次购买多个消耗品的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am allowing user to purchase multiple consumables(of same type) at a time. I have implemented the following code:

- (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;
    }
}

}

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

But the problem is that for each single consumable entry a separate prompt is displayed to ask user to confirm the purchase.

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

Is it possible in IAP to purchase multiple consumables of same type at a time with one prompt for user?

我想到的一个逻辑是在商店中为多个消耗品创建单独的产品,例如一个产品用于两个产品,另一个产品用于三个消耗品。

One logic which I have thought is to create separate products in store for multiple consumables e.g. one product for two and another for three consumables.

请帮助。

谢谢,

推荐答案

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

If they are of the same type, you should use the quantity field. Check out the SKPayment class reference. The maximum value for quantity is 10.


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

To create a SKPayment object with a quantity greater than 1, create a SKMutablePayment object, adjust its quantity property and then add it to the payment queue.

来自文档的示例:

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

这篇关于一次购买多个消耗品的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆