PaymentQueue: updatedTransactions is called when it should not?

I had a strange problem with an in-app purchase ...

After I request product information, sometimes for some reason the paymentQueue: updatedTransactions function is automatically called.

In my storeDidLoad method of my store, I initialize and run the request:

- (void)viewDidLoad { [super viewDidLoad]; productsArray = [[NSArray alloc] init]; [[SKPaymentQueue defaultQueue] addTransactionObserver:self]; NSSet *productIdentifiers = [NSSet setWithObjects:PRODUCT_ID, nil]; productsRequest = [[SKProductsRequest alloc] initWithProductIdentifiers:productIdentifiers]; productsRequest.delegate = self; [productsRequest start]; } 

Then I get the answer:

 - (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response { productsArray = [[NSArray alloc] initWithArray:response.products]; NSLog(@"Products Count: %d",[productsArray count]); NSLog(@"Invalid Products Count: %d",[response.invalidProductIdentifiers count]); if ([productsArray count] > 0) { NSLog(@"Product title: %@" ,[productsArray objectAtIndex:0]); [self hideLoadingView]; } else { UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:@"No products found" message:@"There might have been a problem. Please try again soon." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil]; [alertView show]; [alertView release]; [self hideLoadingView]; [purchaseBtn setEnabled:NO]; } [productsRequest release]; [[NSNotificationCenter defaultCenter] postNotificationName:kInAppPurchaseManagerProductsFetchedNotification object:self userInfo:nil]; } 

Here I expect the process to complete, and wait for the user to click the buy button ... but sometimes (for example, in 70% of cases), I get a warning window about the username and password in the pop-up window to buy the product ... but the user didn’t click anything ... (and if the user has already “logged in”, he buys the item without a request. This is NOT how it should be.

This is a method that is called automatically sometimes:

 - (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions { NSLog(@"updated transaction"); for (SKPaymentTransaction *transaction in transactions) { switch (transaction.transactionState) { case SKPaymentTransactionStatePurchased: NSLog(@"transationStatePurchased"); [self completeTransaction:transaction]; break; case SKPaymentTransactionStateFailed: NSLog(@"transationStateFailed"); [self failedTransaction:transaction]; break; default: break; } } } 

and this is the IBAction of the purchase button:

 -(IBAction)buyItem:(id)sender { [self showLoadingView]; SKPayment *payment = [SKPayment paymentWithProductIdentifier:[(SKProduct *)[productsArray objectAtIndex:0] productIdentifier]]; [[SKPaymentQueue defaultQueue] addPayment:payment]; } } 

I thought that the StoreKit user / password warning window should not be displayed until I call Queue's default addPayment method, which appears ONLY in IBAction.

Any ideas? Thanks!

+4
source share
1 answer

Once you add a transaction watcher, iOS will check the default queue if there is any transaction in progress (which means you haven’t completed it), so it will show a warning window every time there is a transaction until you finish it if You did not take any action to add a new payment.

+8
source

Source: https://habr.com/ru/post/1400685/


All Articles