Ios Objective-C视图在随机时间后弹出

Ios Objective-C视图在随机时间后弹出,ios,objective-c,random,ads,arc4random,Ios,Objective C,Random,Ads,Arc4random,假设John已经使用我的应用程序3-6分钟了。 然后我想弹出一个视图,在我的情况下,包括一个广告 像这样的, AdViewController *adViewController = [[AdViewController alloc] init]; [self presentViewController:adViewController animated:YES completion:nil]; 但是我怎么能让它在一段随机时间后弹出呢?我想我必须处理委托文件并使用arc4random函数

假设John已经使用我的应用程序3-6分钟了。 然后我想弹出一个视图,在我的情况下,包括一个广告

像这样的,

 AdViewController *adViewController = [[AdViewController alloc] init];
 [self presentViewController:adViewController animated:YES completion:nil];
但是我怎么能让它在一段随机时间后弹出呢?我想我必须处理委托文件并使用arc4random函数

约翰看完广告后,他就得把它关掉,但这不是问题所在


有人能给我一个代码示例吗

简单的解决办法是

创建一个NSTimer,让它每300秒5分钟启动一次 NSTimer将启动一个显示弹出窗口的操作。 我不明白为什么这么难理解

//use arc4random() if you need random time


NSTimer *timer2 = [NSTimer scheduledTimerWithTimeInterval:300.0 target:self selector:@selector(rateThisApp) userInfo:nil repeats:YES];

// *********
// ********* RATE APP ***********
// *********
- (IBAction)rateThisApp
{
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Rate this App"
                                                                message:@"Are you enjoying this app? Please leave a rating at the app store and tell us what you think of this app and its features. We would love to hear from you!"
                                                               delegate:self cancelButtonTitle:@"Not Now"
                                                      otherButtonTitles:@"Rate Now", nil];
        [alert show];
        alert.tag = 400;

}


-(void)alertView:(UIAlertView *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (actionSheet.tag == 400)
    {
        if (buttonIndex == 0)
        {
            //dont do anything, user hit cancel
        }
        else if (buttonIndex == 1)
        {
            [[UIApplication sharedApplication]
             openURL:[NSURL URLWithString:@"itms-apps://ax.itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?type=Purple+Software&id=1234567"]];
        }
    }

}

你在谷歌上搜索过这个吗?到目前为止,您尝试了哪些代码来实现这一目标?因此,您有一个想法,我建议您尝试实现它,编写一些代码,如果您仍然有问题,请返回一个更具体的问题。非常感谢。我显然没有想到objective-c中已经有内置计时器。但我仍然对此感到困惑-5或更多!这里的大多数开发人员都很有帮助,但他们希望您在发布问题之前先试用代码、研究、谷歌、阅读。这就是为什么大多数人对你的问题评价很低,我理解。谢谢,下次我会改进我的问题。