Purchasing multiple consumables at a time

不羁的心 提交于 2019-12-12 02:13:42

问题


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.

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.

Kindly help.

Thanks,


回答1:


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.

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.

Example from the docs:

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


来源:https://stackoverflow.com/questions/38817449/purchasing-multiple-consumables-at-a-time

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!