luckystars
luckystars

Reputation: 1754

Is it possible to show iAd after some definite intervals in iOS

I have a requirement for showing iAds in one of amy app, but the catch is it is to be shown after some interval say for 10 or 15 secs, even the interval time is not fixed. I am not getting either the head or tail of this. Is it possible programmatically ? Even if it is possible will it be approved by apple? Thanks for your help in advance.

Upvotes: 0

Views: 139

Answers (1)

Infinity James
Infinity James

Reputation: 4735

Looking through the iAd Programming Guide I cannot find any explicit instruction to not periodically hide and display iAds as you are suggesting.

To achieve this the best way to do it would be through the use of an NSTimer.

I would declare a property:

/** A timer used to time how long an iAd should show. */
@property (nonatomic, strong) NSTimer *iAdTimer;

I would then create a method which starts the timer and displays the iAd:

/**
 * Displays the iAd banner and starts a timer to hide it again.
 */
- (void)displayiAdBanner
{
    NSDate *fireDate = [[NSDate alloc] initWithTimeIntervalSinceNow:15.0f];
    self.iAdTimer = [[NSTimer alloc] initWithFireDate:fireDate interval:0.0f target:self selector:@selector(hideiAdBanner) userInfo:nil repeats:NO];
    [[NSRunLoop currentRunLoop] addTimer:self.iAdTimer forMode:NSRunLoopCommonModes];

    //    show the banner here in whatever way you are currently doing it...
}

Then obviously you need the method to hide the banner:

/**
 * Hides the banner and stops the timer.
 */
- (void)hideiAdBanner
{
    [self.iAdTimer invalidate];
    self.iAdTimer = nil;

    //    hide the banner here
}

Upvotes: 1

Related Questions