Apple have unfortunately rejected my app for not having a restore button. I wanted to have a seamless experience for the user but there are some problems.
- (void)purchaseProUpgrade
{
[[SKPaymentQueue defaultQueue] addTransactionObserver:self];
// User is prompted for iTunes username and password here (1)
[[SKPaymentQueue defaultQueue] restoreCompletedTransactions];
}
// Then this delegate Function Will be fired
- (void) paymentQueueRestoreCompletedTransactionsFinished:(SKPaymentQueue *)queue
{
if( queue.transactions.count == 0 ) {
[self setUpgradeProductId];
// User is prompted for iTunes username and password here (2)
SKPayment *payment = [SKPayment paymentWithProductIdentifier:kInAppPurchaseProUpgradeProductId];
[[SKPaymentQueue defaultQueue] addPayment:payment];
}else {
[[NSNotificationCenter defaultCenter] postNotificationName:kInAppPurchaseManagerTransactionSucceededNotification object:self userInfo:NULL];
}
}
Is the above a good solution? The logic would be:
The problems with this approach are: 1. An additional server call 2. User has to enter details twice.
Has anyone actually implemented a Restore button that they can demonstrate?
No need of implementing your own logic Just implement this
- (IBAction)restorePreviousTransaction:(id)sender {
[[SKPaymentQueue defaultQueue] addTransactionObserver:self];
[[SKPaymentQueue defaultQueue] restoreCompletedTransactions];
}
This will call this method
- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions
{
case SKPaymentTransactionStateRestored:
if ([self respondsToSelector:@selector(restoreTransaction:)]) {
[self restoreTransaction:transaction];
return;
}
This will call these delegate methods for transaction success or failure
- (void)restoreTransaction:(SKPaymentTransaction *)transaction
-(void)paymentQueue:(SKPaymentQueue *)queue restoreCompletedTransactionsFailedWithError:(NSError *)error
-(void)paymentQueueRestoreCompletedTransactionsFinished:(SKPaymentQueue *)queue
Add this code to the page where you had added the restore button:
- (void)paymentQueue:(SKPaymentQueue *)queue restoreCompletedTransactionsFailedWithError:(NSError *)error {
NSLog(@"%@",error);
}
// Call This Function
- (void) checkPurchasedItems
{
[[SKPaymentQueue defaultQueue] addTransactionObserver:self];
[[SKPaymentQueue defaultQueue] restoreCompletedTransactions];
}
//Then this delegate Function Will be fired
- (void) paymentQueueRestoreCompletedTransactionsFinished:(SKPaymentQueue *)queue
{
purchasedItemIDs = [[NSMutableArray alloc] init];
NSLog(@"received restored transactions: %i", queue.transactions.count);
for (SKPaymentTransaction *transaction in queue.transactions)
{
NSString *productID = transaction.payment.productIdentifier;
[purchasedItemIDs addObject:productID];
NSLog(@"%@",purchasedItemIDs);
}
}
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