在应用内购买期间更新hud ivar的问题

时间:2012-08-18 14:34:18

标签: ios5 in-app-purchase mbprogresshud

我最近在我的应用中设置了应用内购买机制。在购买过程中,我想根据两种事件更新一个hud(我正在使用mbprogresshud):我开始购买并获得购买验证。我面临的问题是,在购买完成后,hud永远不会用我想要的那个更新(自定义视图):

  1. 当我点击购买按钮时:
  2. -(IBAction)buyButtonTapped:(id)sender {
    
      self.hud = [[SCLProgressHUD alloc] initWithView:self.view];
        [self.view addSubview:self.hud];
    
        self.hud.labelText = @"Connecting...";
        self.hud.minSize = CGSizeMake(100 , 100);
        [self.hud show:YES];
      ...
    }
    
    1. 当我收到购买成功的通知时:
    2.  -(void)productPurchased:(NSNotification *)notification {     
      self.hud.customView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"checkmark_icon.png"]];     
      self.hud.mode = SCLProgressHUDModeCustomView;
      self.hud.labelText = @"Thanks for your purchase!";        
      ... 
      }
      

      在最后一个方法中设置self.hud.customView属性将触发[self setNeedsLayout];和[self setNeedsDisplay]在hud类中,但我仍然没有观察到任何变化。

      我在这里做错了什么可能的想法?

1 个答案:

答案 0 :(得分:0)

正如 mbprogress hud 自述文件中所述,在主线程上执行任务时更新UI需要稍微延迟才能生效。在我的情况下发生的事情是,hud是一个popover控制器的强大属性,我立即解雇,所以我没有机会看到更新发生。我现在在完成块中解除控制器:

  

- (无效)showAnimated:(BOOL)动画   whileExecutingBlock :( dispatch_block_t)块completionBlock :(无效   (^)())完成

我的代码片段就像解雇一样:

[_hud showAnimated:YES whileExecutingBlock:^(void){
                                          [self.successPurchaseSoundEffect play];
                                          _hud.customView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"checkmark_icon.png"]];
                                          _hud.mode = SCLProgressHUDModeCustomView;
                                          _hud.labelText = @"Thanks!";

                                          // We need to pause the background thread to let the music play and the hud be updated
                                          sleep(1);}
                          completionBlock:^(void){
                                          [self.delegate dismissPurchaseInfoController:self];
}];