objective c - iOS StoreKit - When to call - (void)restoreCompletedTransactions? -


i have lots of 1 time purchase iaps inside of application. users can purchase them fine.

my problem integrating flurry track real purchases versus restoration of purchase, skpaymenttransaction's transactionstate comes skpaymenttransactionstatepurchased rather skpaymenttransactionstaterestored.

apparently skpaymenttransactionstaterestored called when - (void)restorecompletedtransactions, when call method?

my thought process purchase should go this: 1) user selects product, 2) user asked if purchase product x amount. 3) server checks if user has purchased before, , if have restore setting skpaymenttransactionstaterestored. otherwise, process transaction , set skpaymenttransactionstatepurchased. apparently wrong , suppose call - (void)restorecompletedtransactions somewhere in between???

thanks,

will

edit:

originally had posted long, unneeded method needed done, see below, matt helped me figure out variable looking for.

for example, let's imagine user purchased app, bought of non-consumable iap's available, deleted app. when user reinstalls app, want able determine when go "purchase" products again, original (first time) purchase, or restoration purchase?

i have implemented "restore purchases" button, let's user ignores/does not see it, , tries select product have purchased before.

as normal purchase, following:

if ([skpaymentqueue canmakepayments]) {       self.productrequest = [[skproductsrequest alloc] initwithproductidentifiers:[nsset setwithobject:productid]];        self.productrequest.delegate = self;       [self.productrequest start]; } else {      //error message here } 

after user has logged itunes account, app let them know have purchased , restored. following delegate method called:

 -(void)paymentqueue:(skpaymentqueue *)queue updatedtransactions:(nsarray *)transactions {        (skpaymenttransaction *transaction in transactions)     {         switch (transaction.transactionstate)         {             case skpaymenttransactionstatepurchased:             {                 [[skpaymentqueue defaultqueue] finishtransaction:transaction];                 if(transaction.originaltransaction)                 {                     nslog(@"just restoring transaction");                 }                 else                 {                     nslog(@"first time transaction");                 }                  break;             }             default:                 break;         }     } } 

no matter if transaction restoration or first time purchase, transaction.transactionstate going equal skpaymenttransactionstatepurchased.

now point how determine if purchase original or restoration purchase?

simple: seen above, see if transaction.originaltransaction initialized. per apple's note: // valid if state skpaymenttransactionstaterestored.

if skpaymenttransaction's originaltransaction initialized, means there previous transaction. otherwise, transaction original one!

once again, matt pointing me in right direction, , making logic lot cleaner!


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -