Reputation: 663
I have 2 problems when I added the restore method for iAP...
Problem 1: Everytime I open my app a iTunes alert comes up and ask if I wanna login to the iTunes Store. This happens since I add the following restore method:
- (IBAction)Restore:(id)sender {
[[SKPaymentQueue defaultQueue] addTransactionObserver:self];
[[SKPaymentQueue defaultQueue] restoreCompletedTransactions];
}
Now, even when I remove the restore method the alert keeps on coming at startup. It seems that Apple already connects with iTunes at the startup of the app. I wanna make this only when a user hits the purchase or restore button. I read several things on StackOverflow that you have to add something in your AppDelegate so that the app is not connecting automatically but with still no luck.
Problem 2: When testing the iAP on my phone and hit the restore button the item can be restored, even if I didn't purchased it before. Is this normal when testing the restore function with a test account? You should say that Apple have to show alert that the item has never been purchased and cannot be restored?
Can someone please guide me step-by-step with this to make it work?
Thanks in advance.
The code:
- (IBAction)Restore:(id)sender {
[[SKPaymentQueue defaultQueue] addTransactionObserver:self];
[[SKPaymentQueue defaultQueue] restoreCompletedTransactions];
}
-(void)paymentQueueRestoreCompletedTransactionsFinished:(SKPaymentQueue *)queue {
[self unlockFeature];
}
#pragma mark -
#pragma mark SKPaymentTransactionObserver
-(void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions
{
for (SKPaymentTransaction *transaction in transactions)
{
switch (transaction.transactionState) {
case SKPaymentTransactionStatePurchased:
[self unlockFeature];
[[SKPaymentQueue defaultQueue]
finishTransaction:transaction];
break;
case SKPaymentTransactionStateFailed:
NSLog(@"Transaction Failed");
[[SKPaymentQueue defaultQueue]
finishTransaction:transaction];
break;
default:
break;
}
}
}
Upvotes: 1
Views: 1424
Reputation: 175
I had something similar to your first problem whilst I was adding IAP's to an app. It turned out that whilst I had been going through testing it and changing things I had got a backlog of pending transactions, so every time I opened the app it was trying to finish those off. If you sign in, let it do anything it needs, close, reopen and repeat I managed to catch up and it stopped asking me to sign in every time. It might be worth giving that a shot. (I'm trying to dig out the question that I got this answer from).
It is restoring the IAP because you are calling [self unlockFeature] when the restore transaction queue finish's even if it hasn't restored anything:
-(void)paymentQueueRestoreCompletedTransactionsFinished:(SKPaymentQueue *)queue {
[self unlockFeature];
}
You should remove the unlockFeature call and sort the transaction handling in the
-paymentqueue:updatedtransactions:
Add this to the switch:
case SKPaymentTransactionStateRestored:
[self unlockFeature];
[[SKPaymentQueue defaultQueue]
finishTransaction:transaction];
break;
Upvotes: 2