【问题标题】:Using NSTimer / time dependancy in method [duplicate]在方法中使用 NSTimer / 时间依赖性 [重复]
【发布时间】:2017-05-06 16:45:33
【问题描述】:

在我的应用程序中,当用户退出 UIWebView 然后返回时,应用程序会向他们显示一个评分弹出窗口。我在我的方法的if 语句中执行此操作。

- (void)viewWillDisappear
 {
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationDidBecomeActiveNotification object:nil];

 if  (self.appExitedToWebView) {
     [self.presentationController showAdvertsWithOfferID:self.offerDetailViewController.offer.offerID completionBlock:nil];
 }
}

但是,我只想在用户使用 UIWebView 超过 15 分钟时才显示评分。我将如何在我的方法中添加这种依赖关系?我猜这和NSTimer有关?

【问题讨论】:

    标签: ios objective-c nstimer


    【解决方案1】:

    在显示 UIWebView 时调用 start 方法,然后在您提到的时间完成后调用一个名为 timerFired 的方法,然后您可以设置 bool 用户已完成您提到的时间。

    -(void)start
    {
        timer=[NSTimer scheduledTimerWithTimeInterval:yourtime target:self selector:@selector(timerFired) userInfo:nil repeats:YES];
    
    }
    -(void)timerFired
    
    }
    

    【讨论】:

      【解决方案2】:

      你可以使用这个代码

      timer=[NSTimer scheduledTimerWithTimeInterval:yourtime target:self selector:@selector(showAlert) userInfo:nil repeats:NO];
      
      -(void)showAlert {
         [timer invalidate];
         [self.presentationController showAdvertsWithOfferID:self.offerDetailViewController.offer.offerID completionBlock:nil];
      }
      

      【讨论】:

      • 这适合我现有的方法吗?
      • 只需将此代码放在您的 if 条件中..
      猜你喜欢
      • 1970-01-01
      • 2013-11-28
      • 1970-01-01
      • 2016-06-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多