sign in pop up appears again and again sandbox

Hi all,

Sign in pop up appears again and again (sandbox environment). Sometimes after signing is done successfully, the transaction is not happening.


Guys this does not happen all the time. And the following lines are available in all the three states (purchased, failed, restored).



I checked the country selected in the test user account and it's appropriate. It mostly happens when the previous transaction is interrupted.


[[SKPaymentQueue defaultQueue] finishTransaction: transaction];

[[SKPaymentQueue defaultQueue] removeTransactionObserver:self];


Guys please help me out on this.


yours,

Rajai

>appears again and again

If by "again and again" you mean once each time you activate the device - that means StoreKit is trying to handle a request that it thinks was generated by, or responding to, this user - and this user is not currently logged on.


If you mean multiple times each time you activate the device - that usually means you have multiple transactions in the queue because you are not calling finishTransaction on each transaction sent to updatedTransactions.

First of All TQ for the reply.


PBK, This is my code in updatedTransactions.


- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions

{


/

/


if(_isRestore==YES)

{


_isRestore=NO;

[self paymentQueueRestoreCompletedTransactionsFinished:queue];

for (SKPaymentTransaction *transaction in transactions)

{

/

/

switch (transaction.transactionState)

{

case SKPaymentTransactionStatePurchased:

/

[self completeTransaction:transaction];

/

/

break;

case SKPaymentTransactionStateFailed:

[self failedTransaction:transaction];

break;

case SKPaymentTransactionStateRestored:

[self restoreTransaction:transaction];

default:

break;

}

}

}


else

{

for (SKPaymentTransaction *transaction in transactions)

{

/

NSLog(@"Transaction state :%ld",(long)transaction.transactionState);

switch (transaction.transactionState)

{

/

/

case SKPaymentTransactionStatePurchased:

/

[self completeTransaction:transaction];

/

/

break;

case SKPaymentTransactionStateFailed:

[self failedTransaction:transaction];

break;

case SKPaymentTransactionStateRestored:

[self restoreTransaction:transaction];

default:

break;

}

}

}


}






In the methods called in each state these two lines are called.


[[SKPaymentQueue defaultQueue] finishTransaction: transaction];

[[SKPaymentQueue defaultQueue] removeTransactionObserver:self];



Am in the same page man?

It's unclear why you are doing the isRestore thing. But your error is that you are prematurely removing the transaction observer. If StoreKit tries to send you 2 transactions you never handle the second one.

This is not my code I'm just fixing the bugs, So I'm not too certain about things around this.


If the isRestore's value is YES then it directs to th below method.




- (void)paymentQueueRestoreCompletedTransactionsFinished:(SKPaymentQueue *)queue

{

_isPurchaseDone = NO;

if ([queue.transactions count] == 0)

{

[[SKPaymentQueue defaultQueue]removeTransactionObserver:self];

[(ShopViewController*)self.delegate noRestoreAlert];

}

else

{

NSString *lproductID;

_isRestore=YES;

if(!productArray)

productArray =[[NSMutableArray alloc]init];

for(SKPaymentTransaction *transaction in queue.transactions)

{

lproductID = transaction.payment.productIdentifier;

/

[productArray addObject:lproductID];

/

}

}

_isPurchaseDone = YES;


}



I beleive the developer gets the proctid'd from the quue into the productArray for other purposes.



Do you think I should remove the below line, Is that what you are suggesting?. But shouldn't we remove the transaction observer after the finishTransaction:

method.

[[SKPaymentQueue defaultQueue] removeTransactionObserver:self];

Sorry but i just don't have the time to understand your restore code. Good luck! But as a general rule, duplicating code is usually a sign of a mistake.


Regarding the question of removing the transaction observer - no, you should not remove it 'immediately' after the finishTransaction. You should remove it when you deallocate the delegate code and you should do that only when you no longer expect to receive any transactions - I wait 5 seconds after a failed transaction. Actually, some Apple folks argue that you should always maintain a transaction observer and the delegate code - and they cite posts like yours as proof!


The problem is that when a user attempts a purchase with old credit card info the App Store will do two things - it will ask them to update their credit card info and it will queue a 'failed' transaction for the app. After the user updates their credit card info the App Store will ask if they want to complete the purchase. If they say 'yes' then the purchase goes through and the App Store will queue a 'purchased' transaction. When the user is done with the App Store the App Store will send the queue to the device. In rapid succession your updatedTransaction method will get two messages. But in your case it will get only one because the observer will be removed after the failed transactuion is processed. The second transaction awaits being handled.

Thanks for your time mate.


But this is not a duplication of code, this app was developed by another developer it was handed over to me when it was in testing phase.


I got the point about the transaction observer. I'll try to implement your idea. The scenario which you mentioned is an impeccable example, but this doesn't solve our original problem mate. I could cite you a similar discussion for your perusal, check the link below.


https://github.com/j3k0/cordova-plugin-purchase/issues/357

My previous message is being moderated becaus of the link so I removed the http


Thanks for your time mate.


But this is not a duplication of code, this app was developed by another developer it was handed over to me when it was in testing phase.


I got the point about the transaction observer. I'll try to implement your idea. The scenario which you mentioned is an impeccable example, but this doesn't solve our original problem mate. I could cite you a similar discussion for your perusal, search the below provided in google and click the first link(Sorry for the inconvenience) .


github.com/j3k0/cordova-plugin-purchase/issues/357

I don't do Cordova Plugin. Your problem is that you have unfinished transactions. If you want the real horror story - search for 'the endless loop".


The code is duplicated line by line. Here is the equivalent without the duplication:



- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions{
    BOOL thisMightMatter=NO;

    if(_isRestore){
         thisMightMatter=YES;
        _isRestore=NO;
        [self paymentQueueRestoreCompletedTransactionsFinished:queue];
    }

    for (SKPaymentTransaction *transaction in transactions) {
      if(thisMightMatter)NSLog(@"Transaction state :%ld",(long)transaction.transactionState);
        /
        /
        switch (transaction.transactionState)
        {
            case SKPaymentTransactionStatePurchased:
              
                /
              
                [self completeTransaction:transaction];
              
                /
              
                /
              
                break;
            case SKPaymentTransactionStateFailed:
              
                [self failedTransaction:transaction];
              
                break;
            case SKPaymentTransactionStateRestored:
              
                [self restoreTransaction:transaction];
             
            default:
                break;
        }
    }
  }

Mate, sorry for the delay. I tried your idea but it leads to a crash.

Some say this behaviour is normal with in-app purchase.

Please check this video and confirm whether this behaviour is normal or not.

https://www.dropbox.com/s/3ot0e4zg01d3bzf/IMG_2332.MOV?dl=0

sign in pop up appears again and again sandbox
 
 
Q