「アプリ内購入・消耗品」というシステムをやっています。最初は普通に購入できるのですが、次回買おうとするとうまくいきません。そこで、テストユーザーを変更したところ、初回のみ購入することもできました。「SK支払いトランザクションの状態が失敗しました」と表示されましたが、どのように修正すればよいですか?
- (void)buyProduct:(int)myNumber{
SKPayment *payment = [SKPayment paymentWithProductIdentifier:[appDelegate.ArrayProductName objectAtIndex:myNumber]];
[[SKPaymentQueue defaultQueue] addPayment:payment];
[[SKPaymentQueue defaultQueue] addTransactionObserver:self];
}
- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions
{
for (SKPaymentTransaction *transaction in transactions){
switch (transaction.transactionState) {
case SKPaymentTransactionStatePurchasing:
break;
case SKPaymentTransactionStatePurchased:
[self completeTransaction:transaction];
[[SKPaymentQueue defaultQueue] finishTransaction: transaction];
break;
case SKPaymentTransactionStateRestored:
[self restoreTransaction:transaction];
[[SKPaymentQueue defaultQueue] finishTransaction: transaction];
break;
case SKPaymentTransactionStateFailed:
if (transaction.error.code != SKErrorPaymentCancelled){
NSLog(@"An error encounterd : %@",transaction.error.code);
}
break;
default:
break;
}
}
}
- (void)completeTransaction:(SKPaymentTransaction *)transaction {
[self verifyReceipt:(SKPaymentTransaction *)transaction];
}
- (void)restoreTransaction:(SKPaymentTransaction *)transaction {
}
- (BOOL)verifyReceipt:(SKPaymentTransaction *)transaction {
NSString* jsonObjectString = [self encode:(uint8_t *)transaction.transactionReceipt.bytes length:transaction.transactionReceipt.length];
NSString* completeString = [NSString stringWithFormat: @"myurl?receipt=%@", jsonObjectString];
NSURL* urlForValidation = [NSURL URLWithString: completeString];
NSMutableURLRequest* validationRequest = [[NSMutableURLRequest alloc] initWithURL: urlForValidation];
[validationRequest setHTTPMethod: @"GET"];
NSData * responseData = [NSURLConnection sendSynchronousRequest:validationRequest returningResponse: nil error: nil];
NSString* responseString = [[NSString alloc] initWithData: responseData encoding: NSUTF8StringEncoding];
NSLog(@"return data : %@",responseString);
int success = [responseString intValue];
return (success == 0);
}