I'm trying to do the following;
Obtain the previous purchases but only load into the payment queue one which is selected by the user. I don't want the user downloading multiple restored purchases. Apple recommend allowing the user to decide what to restore and this is where I'm stuck.
At the moment, I'm allowing RestoreCompletedTransactions
to be called when the user selects restore but this then means I have to clear the selected paymentqueue. This seems like an unnecessary procedure and causes more problems than it solves. I'm sure there is an easy way of doing this but I've trawled the web for hours looking for a solution and Apple documentation does not give me any reasonable procedure for this. I'd be grateful if anyone can give me some direction here.
My purchase of these Non-Consumables is working fine, its just the restore thats bogging me down.
By the way - its Apple hosted content!
- (IBAction)buyProduct:(id)sender { //checked!!
NSLog(@"Performing in-app purchase: %@",_product);
SKPayment *payment = [SKPayment paymentWithProduct:_product];
[[SKPaymentQueue defaultQueue] addPayment:payment];
}
- (IBAction)Restore:(id)sender {
NSLog(@"Performing in-app restore_product: %@",_product);
NSLog(@"Performing in-app restore_productID: %@",productID);
[self restoreThePurchase];
}
- (BOOL)restoreThePurchase {
// restore the purchase
[[SKPaymentQueue defaultQueue]restoreCompletedTransactions];
return YES;
}
#pragma mark -
#pragma mark SKPaymentTransactionObserver methods
- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions {
for (SKPaymentTransaction *transaction in transactions) {
switch (transaction.transactionState) {
case SKPaymentTransactionStatePurchased: {
NSLog(@"Transaction State Purchased");
[[SKPaymentQueue defaultQueue] startDownloads:transaction.downloads];
[self completeTransaction:transaction];
break;
}
case SKPaymentTransactionStateFailed: {
// transaction didn't work
[self displayAlertViewWithMessage:@"There was a problem with your purchase. Please try again later."];
break;
}
case SKPaymentTransactionStateRestored: {
// purchase has been restored
transactionRestored = [[NSMutableArray alloc] init];
NSLog(@"received restored transactions: %lu", (unsigned long)queue.transactions.count);
for (SKPaymentTransaction *transaction in queue.transactions)
{
{
NSString *aProductID = transaction.payment.productIdentifier;
[transactionRestored addObject:aProductID];
}
NSLog(@"TransactionRestoredArray in PQRCTF : %@", transactionRestored);
NSLog(@"Restore indentifier in PQRCTF : %@", transaction.payment.productIdentifier);
NSLog(@"ProductID in PQRCTF : %@", productID);
NSLog(@"Transaction in PQRCTF : %@", transaction);
NSLog(@"OrignianalTransaction in PQRCTF : %@", transaction.originalTransaction);
NSLog(@"OrignianalTransaction in PQRCTF : %@", transaction.payment.productIdentifier);
if ([transactionRestored containsObject:productID]) {
NSLog(@"Was purchased before!in PQRCTF");
//[self restoreTransaction:transaction];
} else {
[[SKPaymentQueue defaultQueue]finishTransaction:transaction];
}
break;
}
case SKPaymentTransactionStatePurchasing: {
// currently purchasing
break;
}
default:
break;
}
}
}
}