我正在应用程序购买中实现(非消耗型 - 歌曲)。当用户为每首歌曲购买点击购买时,我调用startPurchase 功能。我的歌曲内容通过我的服务器交付。
因为当我购买了一些东西并再次尝试重新购买相同的东西时,它不会被视为购买的恢复。它会进行新的购买。委托方法被多次调用
实际上我的问题是,我点击购买并继续付款,然后购买了该商品。
再次,当我尝试购买相同的商品时,当我点击“确定”时,苹果警报显示为“您已经购买了该商品,点击确定下载”。这不是在SKPaymentTransactionStateRestored下,而是转到SKPaymentTransactionStatePurchased。为什么会发生这种情况? 请帮忙
请帮帮我
- (void)startPurchase:(NSString*)inProductId{
if ([SKPaymentQueue canMakePayments])
{
myProductId = inProductId
SKProductsRequest *productsRequest = [[SKProductsRequest alloc] initWithProductIdentifiers:[NSSet setWithObject:myProductId]];
productsRequest.delegate = self;
[productsRequest start];
}
else {
NSLog(@"Parental-controls are enabled");
}
}
- (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:
(SKProductsResponse *)response {
NSLog(@"response received");
SKProduct *validProduct = nil;
int count = [response.products count];
UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"Message" message:
[NSString stringWithFormat:@"%d",response.products.count] delegate:
self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
[alert release];
if (count > 0) {
validProduct = [response.products objectAtIndex:0];
NSLog(@"products available");
SKPayment *payment = [SKPayment paymentWithProductIdentifier:myProductId];
[[SKPaymentQueue defaultQueue] addTransactionObserver:self];
[[SKPaymentQueue defaultQueue] addPayment:payment];
}
else if (!validProduct) {
NSLog(@"No products available");
}
}
- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions
{
for (SKPaymentTransaction *transaction in transactions)
{
SKPayment *payment = [transaction payment];
if([payment.productIdentifier isEqualToString:myProductId])
{
NSLog(@"%@payement queue payment.productIdentifier",payment.productIdentifier);
switch (transaction.transactionState)
{
case SKPaymentTransactionStatePurchased:
NSLog(@"completeTransaction");
[self completeTransaction:transaction];
break;
case SKPaymentTransactionStateFailed:
NSLog(@"failedTransaction");
[self failedTransaction:transaction];
break;
case SKPaymentTransactionStateRestored:
NSLog(@"restoreTransaction");
[self restoreTransaction:transaction];
default:
break;
}
}
}
}
- (void)provideContent:(NSString *)productIdentifier
{
NSLog(@"Provide Content %@", productIdentifier);
}
- (void)recordTransaction:(SKPaymentTransaction *)transaction {
NSLog(@"inside the recordTransaction");
}
- (void) completeTransaction: (SKPaymentTransaction *)transaction
{
[self recordTransaction: transaction];
[self provideContent: transaction.payment.productIdentifier];
[[SKPaymentQueue defaultQueue] finishTransaction: transaction];
}
- (void) restoreTransaction: (SKPaymentTransaction *)transaction
{
NSLog(@"restoreTransaction transaction inside");
}
- (void) failedTransaction: (SKPaymentTransaction *)transaction
{
if (transaction.error.code != SKErrorPaymentCancelled)
{
if(transaction.error.code == SKErrorUnknown) {
NSLog(@"Unknown Error (%d), product: %@", (int)transaction.error.code, transaction.payment.productIdentifier);
UIAlertView *failureAlert = [[UIAlertView alloc] initWithTitle :@"In-App-Purchase Error:"
message: @"There was an error purchasing this item please try again."
delegate : self cancelButtonTitle:@"OK"otherButtonTitles:nil];
[failureAlert show];
[failureAlert release];
}
if(transaction.error.code == SKErrorClientInvalid) {
NSLog(@"Client invalid (%d), product: %@", (int)transaction.error.code, transaction.payment.productIdentifier);
UIAlertView *failureAlert = [[UIAlertView alloc] initWithTitle :@"In-App-Purchase Error:"
message: @"There was an error purchasing this item please try again."
delegate : self cancelButtonTitle:@"OK"otherButtonTitles:nil];
[failureAlert show];
[failureAlert release];
}
if(transaction.error.code == SKErrorPaymentInvalid) {
NSLog(@"Payment invalid (%d), product: %@", (int)transaction.error.code, transaction.payment.productIdentifier);
UIAlertView *failureAlert = [[UIAlertView alloc] initWithTitle :@"In-App-Purchase Error:"
message: @"There was an error purchasing this item please try again."
delegate : self cancelButtonTitle:@"OK"otherButtonTitles:nil];
[failureAlert show];
[failureAlert release];
}
if(transaction.error.code == SKErrorPaymentNotAllowed) {
NSLog(@"Payment not allowed (%d), product: %@", (int)transaction.error.code, transaction.payment.productIdentifier);
UIAlertView *failureAlert = [[UIAlertView alloc] initWithTitle :@"In-App-Purchase Error:"
message: @"There was an error purchasing this item please try again."
delegate : self cancelButtonTitle:@"OK"otherButtonTitles:nil];
[failureAlert show];
[failureAlert release];
}
}
[[SKPaymentQueue defaultQueue] finishTransaction: transaction];
}