Reputation: 1872
I've read ALL the threads etc. on the internet and still am getting back zero restored transactions when I try to restore purchased products (sandbox environment).
I have created 3 Non-renewing products and 2 sandbox testers through iTunes connect.
I have had zero issues setting up the ability to actually purchase products; all is well.
I have created a "restore purchases" button and am trying to get it to work. I've been testing the following: install app and make purchase. Purchase again and it asks if I want to renew. Delete app and log out of app store. Reinstall app and press restore purchases ... zero!!!
Here's some code I'm using:
-(void)viewDidLoad
{
[super viewDidLoad];
//in-app purchase setup
[[SKPaymentQueue defaultQueue] addTransactionObserver:self];
}
-(void)viewDidAppear:(BOOL)animated
{
//make request for in-app products
if([SKPaymentQueue canMakePayments])
{
SKProductsRequest *request = [[SKProductsRequest alloc] initWithProductIdentifiers:[NSSet setWithObjects:@"product1_id",@"product2_id",@"product3_id",nil]];
request.delegate = self;
[request start];
}
else
{
//alert user
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"..." message:@"Please enable In App Purchase in settings" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
}
}
-(IBAction)restoreTransactionsPressed
{
_refreshRequest = [[SKReceiptRefreshRequest alloc] init];
_refreshRequest.delegate = self;
[_refreshRequest start];
}
-(void)requestDidFinish:(SKRequest *)request
{
if([request isKindOfClass:[SKReceiptRefreshRequest class]])
{
NSLog(@"Got a new receipt... %@",request.description);
[[SKPaymentQueue defaultQueue] restoreCompletedTransactions];
}
}
-(void)request:(SKRequest *)request didFailWithError:(NSError *)error
{
NSLog(@"%@",error.description);
}
-(void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions
{
NSLog(@"updatedTransactions");
for(SKPaymentTransaction *transaction in transactions)
{
NSLog(@"updatedTransaction:%@ ... state:%@",transaction.originalTransaction.payment.productIdentifier,transaction.transactionState);
switch(transaction.transactionState)
{
case SKPaymentTransactionStatePurchased:
NSLog(@"SKPaymentTransactionStatePurchased");
//unlock feature code
[[SKPaymentQueue defaultQueue] finishTransaction:transaction];
break;
case SKPaymentTransactionStateFailed:
NSLog(@"SKPaymentTransactionStateFailed");
[[SKPaymentQueue defaultQueue] finishTransaction:transaction];
break;
case SKPaymentTransactionStateRestored:
NSLog(@"SKPaymentTransactionStateRestored");
[[SKPaymentQueue defaultQueue] finishTransaction:transaction];
break;
default:
break;
}
}
}
-(void)paymentQueueRestoreCompletedTransactionsFinished:(SKPaymentQueue *)queue
{
NSLog(@"paymentQueueRestoreCompletedTransactionsFinished");
NSLog(@"received restored transactions: %i", (int)queue.transactions.count);
for(SKPaymentTransaction *transaction in queue.transactions)
{
NSLog(@"transaction:%@",transaction);
}
}
-(void)paymentQueue:(SKPaymentQueue *)queue restoreCompletedTransactionsFailedWithError:(NSError *)error
{
NSLog(@"restoreCompletedTransactionsFailedWithError %@",error);
}
Why do I always get back zero restored transactions?
it seems that "restoreCompletedTransactions" isn't in turn calling - paymentQueue:updatedTransactions: if that helps.
I'm unsure that SKReceiptRefreshRequest is necessary, but I've tried both refreshing the receipt before restoring and not refreshing the receipt before restoring.
Please don't post links to thread. I've investigated this for a few Days now! Some people claim that Apple's Sandbox had issues in the past ... could this be the reason? tyvm in advanced; all help is appreciated!
Upvotes: 0
Views: 991
Reputation: 2854
According to Apple's documentation, you can't restore non-renewing subscriptions. Also, have a read here for a more detailed explanation.
Upvotes: 2