2010-09-02 60 views
0

当我的实现SKPaymentTransactionObserver的对象被调用时,我似乎无法让我的UI更新。SKPaymentTransactionObserver方法的UI更新

具体来说,我有一个(UILabel *)debugLabel在我的用户界面(所有通过IB连接)。我有我的执行观察者协议:

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

    NSLog(@"paymentQueue: current thread is main thread: %@", [[NSThread currentThread] isMainThread][email protected]"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 
    } 
} 

[spViewController.storeViewController transactionComplete:transaction]被执行,但的UILabel不显示分配的文本。

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

    // other UI updates omitted for brevity 
} 

当代码执行时,NSLog将字符串转储到控制台,但UILabel未更新。我已经确认SKPaymentTransactionObserver的回调函数在主线程中发生 - 所以UI应该更新。 (对吧?)

什么给?它一定会错过简单的东西?

感谢您的任何见解,指针等

回答

0

事实证明,更新到UI都在相同的运行循环发生。运行循环完成后,UI会更新 - 看起来一次完成。

我解决了这个问题,通过一个NSOperation将事务处理移动到它自己的线程中。从NSOperation中,我根据需要更新UI(通过调用回主线程)。

感谢您的意见!