在方法中使用 NSTimer / 时间依赖

Using NSTimer / time dependancy in method

目前在我的应用程序中,当用户退出 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?

有关

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

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

}
-(void)timerFired

}

您可以使用此代码

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];
}