tags:

views:

34

answers:

1

I cannot seem to get my UI to update when my object that implements SKPaymentTransactionObserver is called.

Specifically, I have a (UILabel *)debugLabel in my UI (all wired up via IB). I have my implementation of the observer protocol:

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

    NSLog(@"paymentQueue: current thread is main thread: %@", [[NSThread currentThread] isMainThread]?@"YES":@"NO");

    for (SKPaymentTransaction *transaction in transactions) {
        if (transaction.transactionState == SKPaymentTransactionStatePurchased) {


            // if the store is still being viewed, update appropriately
            if(spViewController.storeViewController) {
                [spViewController.storeViewController transactionComplete:transaction];
            }
        }
        // other transactionStates omitted for brevity
    }
}

The [spViewController.storeViewController transactionComplete:transaction] is executed, but the UILabel does not display the assigned text.

- (void) transactionComplete:(SKPaymentTransaction *) transaction {
    NSLog(@"CBTSVC transactionComplete");
    debugLabel.text = @"CBTSVC transactionComplete";

    // other UI updates omitted for brevity
}

When the code executes, the NSLog dumps the string to the console, but the UILabel is not updated. I've confirmed that the callbacks made to the SKPaymentTransactionObserver are occuring on the main thread -- so the UI should be updating. (Right?)

What gives? It must be missing something simple?

Thanks for any insights, pointers, etc.

A: 

It turns out that the updates to the UI are all occurring in the same run loop. When the run loop completes, the UI updates -- seemingly all at once.

I solved this by moving the transaction processing into its own thread via an NSOperation. From the NSOperation, I'm updating the UI as needed (by making calls back to the main thread).

Thanks for the views!

TomH