iOS 배너 광고
배너 광고 노출하기
광고 크기를 적용한 광고 유닛 ID로 AdropBanner
를 초기화하고, 광고를 로드하세요.
class ViewController: UIViewController {
@IBOutlet weak var adContainer: UIView!
override func viewDidLoad() {
super.viewDidLoad()
// 추가 설정은 먼저 view를 로드한 후 진행하세요.
let bannerView = AdropBanner(unitId: "ADROP_PUBLIC_TEST_UNIT_ID")
bannerView.delegate = self
bannerView.load()
adContainer.addSubview(bannerView)
bannerView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
bannerView.translatesAutoresizingMaskIntoConstraints = false
bannerView.frame = adContainer.bounds
}
}
extension ViewController: AdropBannerDelegate {
func onAdReceived(_ banner: AdropAds.AdropBanner) {
print("onAdReceived")
}
func onAdClicked(_ banner: AdropAds.AdropBanner) {
print("onAdClickced")
}
func onAdFailedToReceive(_ banner: AdropAds.AdropBanner, _ error: AdropAds.AdropErrorCode) {
print("onAdFailedToReceive \(AdropErrorCodeToString(code: error))")
}
}
@interface ViewController (AdropAds) <AdropBannerDelegate>
@end
@implementation ViewController (AdropAds)
- (void)onAdReceived:(AdropBanner * _Nonnull)banner {
NSLog(@"onAdReceived");
}
- (void)onAdClicked:(AdropBanner * _Nonnull)banner {
NSLog(@"onAdClicked");
}
- (void)onAdFailedToReceive:(AdropBanner * _Nonnull)banner :(enum AdropErrorCode)error {
NSLog(@"onAdFailedToReceive");
}
@end
@interface ViewController ()
@property (weak, nonatomic) IBOutlet UIView *adContainerView;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
AdropBanner* banner = [[AdropBanner alloc] initWithUnitId:@"ADROP_PUBLIC_TEST_UNIT_ID"];
banner.delegate = self;
[banner load];
[_adContainerView addSubview:banner];
banner.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
banner.translatesAutoresizingMaskIntoConstraints = false;
banner.frame = _adContainerView.bounds;
}
@end
class AdropBannerWrapper: AdropBannerDelegate {
let bannerRep: AdropBannerRepresented
init(){
bannerRep = AdropBannerRepresented(unitId: "ADROP_PUBLIC_TEST_UNIT_ID")
bannerRep.banner.delegate = self
}
func onAdReceived(_ banner: AdropAds.AdropBanner) {
print("onAdReceived")
}
func onAdClicked(_ banner: AdropAds.AdropBanner) {
print("onAdClicked")
}
func onAdFailedToReceive(_ banner: AdropAds.AdropBanner, _ error: AdropAds.AdropErrorCode) {
print("onAdFailedToReceive \(AdropErrorCodeToString(code: error))")
}
}
struct ContentView: View {
var adropBannerWrapper = AdropBannerWrapper()
var body: some View {
ZStack{
VStack {
Spacer()
Image(systemName: "globe")
.imageScale(.large)
.foregroundColor(.accentColor)
Text("Adrop Ads")
Button {
adropBannerWrapper.bannerRep.banner.load()
} label: {
Text("requestAd")
}
.padding(.all)
Spacer()
}
VStack {
Spacer()
adropBannerWrapper.bannerRep.frame(height: 80)
}
}
}
}
Last updated