40

I got so far: After a reinstall, a user needs to click "buy feature", then he gets scared with the $0.99 question, then has to login and then gets told the feature is already bought and he gets it for free.

I know apple is a religion and users are strong believers, but isn't there a better way? :-) What I want is to check for the feature without actually buying it. Letting the user enter his account info seems to be neccessary, maybe buy a $0.00 feature? or is there a method somewhere that does this?

I'm using MKStoreKit for the whole In-App-Purchase, but any solution would be great.


UPDATE

thanx to darvids0n, your method solved my problem! here's some working code for others trying the same:

- (void)removePreviousPurchases { //just for sandbox testing
    [[MKStoreManager sharedManager] removeAllKeychainData];
}

- (void)restorePreviousPurchases { //needs account info to be entered
    if([SKPaymentQueue canMakePayments]) {
        [[MKStoreManager sharedManager] restorePreviousTransactionsOnComplete:^(void) {
             NSLog(@"Restored.");
             /* update views, etc. */
        }
        onError:^(NSError *error) {
            NSLog(@"Restore failed: %@", [error localizedDescription]);
            /* update views, etc. */
        }];
    }
    else
    {
        NSLog(@"Parental control enabled");
        /* show parental control warning */
    }
}
iwasrobbed
  • 46,496
  • 21
  • 150
  • 195
Daniel Brown
  • 1,134
  • 1
  • 13
  • 27

2 Answers2

34

If the $0.99 item is non-consumable, then you should provide a "Restore Purchases" button (or similar) which calls

[[SKPaymentQueue defaultQueue] restoreCompletedTransactions];

Assuming you've added a transaction observer already, and implemented the protocol including a case to handle a restored transaction (with state SKPaymentTransactionStateRestored) this will work.

  • Thank you, finally found the MKStore-Kit method to use for this! (see edit to my question) – Daniel Brown Oct 14 '11 at 00:43
  • If I have 10 non-consumable purchase ids and out of which 4 are purchased by user. During restore, how can I find out which ones are previously purchased and which ones are not? – Satyam Dec 03 '12 at 09:51
  • @Satyamsvv You won't get callbacks for the purchases your user has not bought. You will only get 4 updated transactions in the `SKPaymentTransactionObserver` method [`-paymentQueue:updatedTransactions:`](http://developer.apple.com/library/ios/documentation/StoreKit/Reference/SKPaymentTransactionObserver_Protocol/Reference/Reference.html#//apple_ref/doc/uid/TP40008262-CH1-SW3), and the `transactionState` of these will be `SKPaymentTransactionStateRestored`. –  Dec 04 '12 at 01:25
  • Unfortunately I'm not getting paymentQueue:updatedTransactions: call at all. I posted my question here: http://stackoverflow.com/questions/13686919/ios6-in-app-purchase-with-download-from-apple-server can you please verify and tell me what am I doing wrong? – Satyam Dec 04 '12 at 02:16
  • Hi @darvids0n, how to check if their are no items to retore and display a suitable message to user. – Ranjit Feb 20 '13 at 07:05
  • Still do this, but also set a `BOOL restoredItems = NO;` on your transaction observer, and if you restore any items set it to `YES`. When you get the `paymentQueueRestoreCompletedTransactionsFinished:` message on your observer, check if `restoredItems` is still `NO` and display a message if it is. –  Feb 21 '13 at 00:57
11

Add these two methods :

[[SKPaymentQueue defaultQueue] addTransactionObserver:self];

[[SKPaymentQueue defaultQueue]restoreCompletedTransactions];
j0k
  • 22,600
  • 28
  • 79
  • 90
manish
  • 119
  • 1
  • 2