我允许用户一次购买多个消耗品(相同类型)。我已经实现了以下代码:
- (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是否可以一次性向用户购买多个相同类型的消耗品?
我想到的一个逻辑是在商店中为多个消耗品创建单独的产品,例如一个产品用于两个产品,另一个产品用于三个消耗品。
请帮助。
谢谢,
答案 0 :(得分:1)
如果它们属于同一类型,则应使用数量字段。查看SKPayment
课程参考。数量的最大值为10。
要创建数量大于1的SKPayment对象,请创建SKMutablePayment对象,调整其数量属性,然后将其添加到付款队列。
文档示例:
SKMutablePayment *myPayment = [SKMutablePayment paymentWithProduct: myProduct];
myPayment.quantity = 2;
[[SKPaymentQueue defaultQueue] addPayment:myPayment];