iOS Banner - adxcorp/ADXLibrary_Integration GitHub Wiki
Banner Integration
1) 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์๋ ๊ด๊ณ ๊ฐ ์ฑ๊ณต์ ์ผ๋ก ๋ก๋ ๋์์ ๋๋ modal view๊ฐ present ๋๊ฑฐ๋ dismiss ๋ ๋ ๋ฑ, ์ฌ๋ฌ๊ฐ์ง ์ด๋ฒคํธ callback์ด ์กด์ฌํฉ๋๋ค. MPAdview.h์ MPAdViewDelegate protocol์ ํ์ธํด๋ณด์๋ฉด ์ด๋ฌํ callback method์ ๋ฆฌ์คํธ๋ฅผ ํ์ธํ์ค ์ ์์ต๋๋ค. ํ์์ ๋ฐ๋ผ ์ฌ์ฉํด์ฃผ์ธ์.
3) Handling rotation
rotation ์ง์์ด ํ์ํ์๋ค๋ฉด orientation์ด ๋ณ๊ฒฝ๋ ๋์ adView์ rotateToOrientation: ํจ์๋ฅผ ํธ์ถํด์ฃผ์ธ์. ๋ช๋ช ์ผ์ด์ค์์๋ (e.g. iAd) ํ์ ํ ๋ ๊ด๊ณ ์ปจํ
์ธ ์ ์ฌ์ด์ฆ๊ฐ ๋ณ๊ฒฝ๋ ์ ์์ต๋๋ค. ์ด๋ฌํ ์ผ์ด์ค๋ฅผ ์ํ์ฌ orientation์ด ๋ณ๊ฒฝ๋ ํ ์ฌ์ด์ฆ์ ํฌ์ง์
์ ๋ค์ ์ก์์ฃผ์ธ์.
- (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);
}