iOS8:实现iAd Singleton

时间:2015-01-11 13:52:29

标签: ios ios8 singleton iad

我正在努力解决这个问题。我已正确添加子视图并且没有错误,但是没有显示任何iAd,即使方法bannerViewDidLoadAd肯定被调用。我有什么建议我做错了吗?

#import "Advertisments.h"

@implementation Advertisments

+ (id)sharedManager {
    static Advertisments *sharedMyManager = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        sharedMyManager = [[self alloc] init];
    });
    return sharedMyManager;
}

- (id)init {
    if (self = [super init]) {
        _bannerView = [[ADBannerView alloc] initWithAdType:ADAdTypeBanner];

        CGRect screenBounds = [[UIScreen mainScreen] bounds];

        self.bannerView.center = CGPointMake(screenBounds.size.width / 2.0, screenBounds.size.height + 25.0);

        _bannerView.delegate = self;
    }
    return self;
}

- (void)bannerViewDidLoadAd:(ADBannerView *)banner
{
    CGRect screenBounds = [[UIScreen mainScreen] bounds];

    [UIView animateWithDuration:0.5
                     animations:^{
                         self.bannerView.center = CGPointMake(screenBounds.size.width / 2.0, screenBounds.size.height - 25.0);
                     }];
}

- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error
{
    CGRect screenBounds = [[UIScreen mainScreen] bounds];

    [UIView animateWithDuration:0.5
                     animations:^{
                         self.bannerView.center = CGPointMake(screenBounds.size.width / 2.0, screenBounds.size.height + 25.0);
                     }];
}

在我的视图中控制器的viewDidLoad方法:

//Add ads
    [self.view addSubview:[[Advertisments sharedManager] bannerView]];

0 个答案:

没有答案