Hi I need to implement the restore functionality in Inapp-Purchase, for this made a button "Restore" which is calling method
-(void)restorePurchasedProductsWithProductId:(NSString*)prodID
{
_productIdsArray = [[NSMutableArray alloc] init];
productID = [prodID retain];
[[SKPaymentQueue defaultQueue] restoreCompletedTransactions];
}
It gives me a popup to enter the password of apple id.And after doing that nothing happens.
I read somewhere that it calls
- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions
So i did like this
- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions
{
NSLog(@"paymentQueue");
for (SKPaymentTransaction *transaction in transactions)
{
switch (transaction.transactionState)
{
case SKPaymentTransactionStatePurchased:
[self completeTransaction:transaction];
break;
case SKPaymentTransactionStateFailed:
[self failedTransaction:transaction];
break;
case SKPaymentTransactionStateRestored:
NSLog(@"restored");
[self restoreTransaction:transaction];
break;
default:
break;
}
}
}
But the problem is the above method is not calling neither this
- (void)paymentQueueRestoreCompletedTransactionsFinished:(SKPaymentQueue *)queue
nor
-(void)paymentQueue:(SKPaymentQueue *)queue restoreCompletedTransactionsFailedWithError:(NSError *)error
I have also included the required protocols,
Can some body help me why these delegate methods are not calling for restore process. I am trying it with test account.
You need to make sure the class that implements paymentQueueRestoreCompletedTransactionsFinished:
and paymentQueue: restoreCompletedTransactionsFailedWithError:
is registered as an observer for your payment queue.
If you've written this code in a UIViewController
, try adding this in your viewDidLoad
:
[[SKPaymentQueue defaultQueue] addTransactionObserver:self];
and in viewDidDisappear
:
[[SKPaymentQueue defaultQueue] removeTransactionObserver:self];
I also am facing a problem like one;
After research & modification, I realized that:
[[SKPaymentQueue defaultQueue] finishTransaction:transaction]
method is not implemented immediately.
Normally, i check transaction.transactionReceipt and send it to my server and after all that I send a callback to finish Transaction. Finally, i understood the problem not calling finish transaction immediately. When i change my code, my app works.
Interesting part was, when i test in sandbox environment, everything works fine. However, in AppStore app did not work well. When i made this modification, my problem was solved.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With