سؤال

Let's say John has been using my app for 3-6 minutes. Then I'd like a view to pop up that would in my case, include an advertisement.

Something like this,

 AdViewController *adViewController = [[AdViewController alloc] init];
 [self presentViewController:adViewController animated:YES completion:nil];

But how can I let it pop up after some random time? I guess I have to work with the delegate files and use the arc4random function.

After John has viewed the advertisement, he'd then have to close it, but that's not the problem..

Can someone give me a code example?

هل كانت مفيدة؟

المحلول

The simple solution is to

  • Create a NSTimer and let it fire every 300 secs (5 mins)
  • NSTimer will fire an action that shows your pop-up.

I don't get it why was this so difficult to understand?

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

}
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top