Mert Karabulut
Mert Karabulut

Reputation: 63

Anything to active iAd?

I have finished my first application. I put iAd banners on it. And active iAd from iTunnes Connect.

I learned to add iAd from this tutorial. http://www.youtube.com/watch?v=fP2ijcXbCz4

Do I need to add something else to my code? Will ads be shown automatically?

@interface TOCGMainViewController () <ADBannerViewDelegate>

@property (strong, nonatomic) IBOutlet ADBannerView *iAdBanner;

@end

@implementation TOCGMainViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    if ([[ UIScreen mainScreen ] bounds ].size.height == 568 ) {
        nibNameOrNil = [NSString stringWithFormat:@"%@_568", nibNameOrNil ?: @"TOCGMainViewController"];
    }

    if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {

    }

    if ([ADBannerView instancesRespondToSelector:@selector(initWithAdType:)]) {
        self.iAdBanner = [[ADBannerView alloc] initWithAdType:ADAdTypeBanner];
    } else {
        self.iAdBanner = [[ADBannerView alloc] init];
    }

    return self;
}

... ... ...

#pragma mark - ADBannerViewDelegate

- (void)bannerViewDidLoadAd:(ADBannerView *)banner {

    NSUserDefaults *saveApp = [NSUserDefaults standardUserDefaults];
    bool saved = [saveApp boolForKey:k_Save];

    if (!saved) {
        [UIView beginAnimations:nil context:NULL];
        [UIView setAnimationDuration:1];
        [banner setAlpha:1];
        [UIView commitAnimations];

    } else {
        banner.hidden = YES;
        [banner removeFromSuperview];
        banner = nil;
        banner.delegate = nil;
    }
}

- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error {

    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:1];
    [banner setAlpha:0];
    [UIView commitAnimations];
}


@end

Upvotes: 0

Views: 62

Answers (1)

Sebastian Wramba
Sebastian Wramba

Reputation: 10127

To test your iAd code, you can simply run the app on the simulator or your device. If you set up everything correctly, you should see a demo banner that indicates this. This will be replaced with the actual ads when the app goes into the store.

Upvotes: 1

Related Questions