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



目前在我的应用程序中,当用户退出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,然后您可以将用户设置为用户已完成您提到的时间。

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

最新更新