(EN) iOS Banner - adxcorp/ADXLibrary_Integration GitHub Wiki
Banner Integration
1) Implementing Banner Ad
MyViewController.h
#import "MPAdView.h"
@interface MyViewController : UIViewController <MPAdViewDelegate>
@property (nonatomic) MPAdView *adView;
@end
MyViewController.m
#import "MyViewController.h"
@implementation MyViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.adView = [[MPAdView alloc] initWithAdUnitId:@"<YOUR_ADUNIT_ID_HERE>"
size:MOPUB_BANNER_SIZE];
self.adView.delegate = self;
self.adView.frame = CGRectMake((self.view.bounds.size.width - MOPUB_BANNER_SIZE.width) / 2,
self.view.bounds.size.height - MOPUB_BANNER_SIZE.height,
MOPUB_BANNER_SIZE.width, MOPUB_BANNER_SIZE.height);
[self.view addSubview:self.adView];
[self.adView loadAd];
}
#pragma mark - <MPAdViewDelegate>
- (UIViewController *)viewControllerForPresentingModalView {
return self;
}
...
@end
2) Delegate Method
MPAdViewDelegate
provides various callbacks, such as when ad has been successfully loaded or when modal view is presented or dismissed. Please refer to callback methods that are found by looking at MPAdViewDelegate
protocol in MPAdview.h
and use them appropriately to your needs.
3) Handling rotation
In order to rotate, call adView
's rotateToOrientation:
method when orientation changes. In some cases, such as iAD
, content size may change when rotated. So make sure to update size and position after orientation changes.
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
duration:(NSTimeInterval)duration {
[self.adView rotateToOrientation:toInterfaceOrientation];
}
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
CGSize size = [self.adView adContentViewSize];
CGFloat centeredX = (self.view.bounds.size.width - size.width) / 2;
CGFloat bottomAlignedY = self.view.bounds.size.height - size.height;
self.adView.frame = CGRectMake(centeredX, bottomAlignedY, size.width, size.height);
}