我在同一页面上有一个包含多个应用内内容的应用。当我购买一个已显示已经购买的内容时,即使我不购买所有这些内容。
- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions
{
NSLog(@"[transactions count] : - %d ", [transactions count]);
for (SKPaymentTransaction *transaction in transactions)
{
switch (transaction.transactionState)
{
case SKPaymentTransactionStatePurchased:
[self completeTransaction:transaction];
break;
case SKPaymentTransactionStateFailed:
[self failedTransaction:transaction];
break;
case SKPaymentTransactionStateRestored:
[self restoreTransaction:transaction];
default:
break;
}
}
}
答案 0 :(得分:2)
您需要在App购买中创建多个按钮,然后为它们分配不同的标签以识别它们。 这是示例代码:
- (void)purchaseProUpgrade{
SKPayment *payment;
if(btnTag ==0){
payment = [SKPayment paymentWithProductIdentifier:kInAppPurchaseProUpgradeProductId1];
}
else if(btnTag ==1){
payment = [SKPayment paymentWithProductIdentifier:kInAppPurchaseProUpgradeProductId2];
}
[[SKPaymentQueue defaultQueue] addPayment:payment];
}
// saves a record of the transaction by storing the receipt to disk
-(void)recordTransaction:(SKPaymentTransaction *)transaction{
if(btnTag == 0){
if ([transaction.payment.productIdentifier isEqualToString:kInAppPurchaseProUpgradeProductId1]){
[[NSUserDefaults standardUserDefaults] setValue:transaction.transactionReceipt forKey:@"proUpgradeTransactionReceipt" ];
[[NSUserDefaults standardUserDefaults] synchronize];
}
}
else if(btnTag == 1){
if ([transaction.payment.productIdentifier isEqualToString:kInAppPurchaseProUpgradeProductId2])
{
// save the transaction receipt to disk
[[NSUserDefaults standardUserDefaults] setValue:transaction.transactionReceipt forKey:@"proUpgradeTransactionReceipt" ];
[[NSUserDefaults standardUserDefaults] synchronize];
}
}
}
-(void)finishTransaction:(SKPaymentTransaction *)transaction wasSuccessful:(BOOL)wasSuccessful{
[[SKPaymentQueue defaultQueue] finishTransaction:transaction];
NSDictionary *userInfo = [NSDictionary dictionaryWithObjectsAndKeys:transaction, @"transaction" , nil];
if (wasSuccessful) {
[[NSNotificationCenter defaultCenter] postNotificationName:kInAppPurchaseManagerTransactionSucceededNotification object:self userInfo:userInfo];
if(btnTag == 0){
//write ur code
}
else if(btnTag == 1){
//write ur code
}
}
else
{
[[NSNotificationCenter defaultCenter] postNotificationName:kInAppPurchaseManagerTransactionFailedNotification object:self userInfo:userInfo];
}
}
这将解决您的问题...
答案 1 :(得分:0)
请在此处查看此Rey Wenderlich最佳教程,其中介绍了使用多种产品完整实施应用内购买。