In addition to adding restoreCompletedTransactions
, you need to handle how your iaps are actually restored to the user and how the content is provided to the user.
Basically, you need to recall the way you provide the item to your user when they originally purchased it.
Here is a good tutorial.
For example, this is how I restore products in one of my apps.
Restore Transaction
- (void)restoreTransaction:(SKPaymentTransaction *)transaction
{
isRestoring = YES;
[self recordTransaction: transaction];
/* This is where I provide the content to the user: */
[self provideContent: transaction.originalTransaction.payment.productIdentifier];
[[SKPaymentQueue defaultQueue] finishTransaction: transaction];
}
Transaction Completed
- (void)completeTransaction:(SKPaymentTransaction *)transaction
{
[self recordTransaction: transaction];
[self provideContent: transaction.payment.productIdentifier];
[[SKPaymentQueue defaultQueue] finishTransaction: transaction];
}
Payment Queue
- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions
{
for (SKPaymentTransaction *transaction in transactions)
{
switch (transaction.transactionState)
{
case SKPaymentTransactionStatePurchased:
[self completeTransaction:transaction];
break;
case SKPaymentTransactionStateFailed:
if (transaction.error.code == SKErrorPaymentCancelled) {
/// user has cancelled
[[NSNotificationCenter defaultCenter] postNotificationName:@"hideRestoring" object:nil];
}
[self failedTransaction:transaction];
break;
case SKPaymentTransactionStateRestored:
[self restoreTransaction:transaction];
default:
break;
}
}
}
Provide the Content
- (void)provideContent:(NSString *)productIdentifier
{
int index;
NSMutableDictionary * purchased = [NSMutableDictionary dictionaryWithContentsOfFile:EXTRAS_PATH];
NSArray * availableProducts = [NSArray arrayWithContentsOfURL:[NSURL URLWithString:SCANNER_IN_APP_PURCHASES]];
if ( isRestoring )
{
for ( index = 0; index < [availableProducts count]; index++ )
{
//NSLog(@"productIdentifier: %@",productIdentifier);
//NSLog(@"Product: %@",[availableProducts objectAtIndex:index]);
if ( [productIdentifier isEqualToString:[[availableProducts objectAtIndex:index] objectForKey:@"BundleID"]] )
{
[purchased setObject:[availableProducts objectAtIndex:index] forKey:productIdentifier];
[purchased writeToFile:EXTRAS_PATH atomically:YES];
[_purchasedProducts addObject:productIdentifier];
}
}
}
else
{
index = [[[NSUserDefaults standardUserDefaults] objectForKey:@"kTempProductPurchasingIndex"] intValue];
if ( [productIdentifier isEqualToString:[[availableProducts objectAtIndex:index] objectForKey:@"BundleID"]] )
{
[purchased setObject:[availableProducts objectAtIndex:index] forKey:productIdentifier];
[purchased writeToFile:EXTRAS_PATH atomically:YES];
[_purchasedProducts addObject:productIdentifier];
}
}
[[NSNotificationCenter defaultCenter] postNotificationName:kProductPurchasedNotification object:productIdentifier];
}