iOS 전면 광고
전면 광고 노출하기
Ad type
Ad unit ID
Interstitial
PUBLIC_TEST_UNIT_ID_INTERSTITIAL
전면 Example 구현 예시
필요한 파라미터 정의
struct AdropUnitId {
// 전면 광고 유닛 ID (실제 발급받은 ID로 교체)
static let INTERSTITIAL_IMAGE = "YOUR_INTERSTITIAL_UNIT_ID"
}@interface AdropUnitId : NSObject
+ (NSString *)INTERSTITIAL_IMAGE;
@end전면 광고 구현
import AdropAds
class ViewController: UIViewController {
private var interstitialAd: AdropInterstitialAd?
override func viewDidLoad() {
super.viewDidLoad()
// 전면 광고 로드
loadInterstitialAd()
// 버튼 클릭 시 광고 표시
setupShowButton()
}
private func loadInterstitialAd() {
interstitialAd = AdropInterstitialAd(unitId: "PUBLIC_TEST_UNIT_ID_INTERSTITIAL")
interstitialAd?.delegate = self
interstitialAd?.load()
}
private func showInterstitialAd() {
if interstitialAd?.isLoaded == true {
interstitialAd?.show(fromRootViewController: self)
} else {
print("광고가 아직 로드되지 않았습니다")
// 광고 재로드
loadInterstitialAd()
}
}
}
extension ViewController: AdropInterstitialAdDelegate {
func onAdReceived(_ ad: AdropInterstitialAd) {
print("전면 광고 로드 성공: \\(ad.unitId)")
}
func onAdFailedToReceive(_ ad: AdropInterstitialAd, _ error: AdropErrorCode) {
print("전면 광고 로드 실패: \\(error)")
}
func onAdDidPresentFullScreen(_ ad: AdropInterstitialAd) {
print("전면 광고 표시됨")
}
func onAdDidDismissFullScreen(_ ad: AdropInterstitialAd) {
print("전면 광고 닫힘")
// 새 광고 미리 로드
loadInterstitialAd()
}
func onAdClicked(_ ad: AdropInterstitialAd) {
print("전면 광고 클릭됨")
}
func onAdImpression(_ ad: AdropInterstitialAd) {
print("전면 광고 노출 확인됨")
}
func onAdFailedToShowFullScreen(_ ad: AdropInterstitialAd, _ error: AdropErrorCode) {
print("전면 광고 표시 실패: \\(error)")
}
}#import <AdropAds/AdropAds.h>
@interface ViewController () <AdropInterstitialAdDelegate>
@property (strong, nonatomic) AdropInterstitialAd *interstitialAd;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// 전면 광고 로드
[self loadInterstitialAd];
// 버튼 설정
[self setupShowButton];
}
- (void)loadInterstitialAd {
self.interstitialAd = [[AdropInterstitialAd alloc] initWithUnitId:@"PUBLIC_TEST_UNIT_ID_INTERSTITIAL"];
self.interstitialAd.delegate = self;
[self.interstitialAd load];
}
- (void)showInterstitialAd {
if (self.interstitialAd && self.interstitialAd.isLoaded) {
[self.interstitialAd showFromRootViewController:self];
} else {
NSLog(@"광고가 아직 로드되지 않았습니다");
// 광고 재로드
[self loadInterstitialAd];
}
}
// AdropInterstitialAdDelegate 메서드들
- (void)onAdReceived:(AdropInterstitialAd *)ad {
NSLog(@"전면 광고 로드 성공: %@", ad.unitId);
}
- (void)onAdFailedToReceive:(AdropInterstitialAd *)ad :(enum AdropErrorCode)error {
NSLog(@"전면 광고 로드 실패: %ld", (long)error);
}
- (void)onAdDidPresentFullScreen:(AdropInterstitialAd *)ad {
NSLog(@"전면 광고 표시됨");
}
- (void)onAdDidDismissFullScreen:(AdropInterstitialAd *)ad {
NSLog(@"전면 광고 닫힘");
// 새 광고 미리 로드
[self loadInterstitialAd];
}
- (void)onAdClicked:(AdropInterstitialAd *)ad {
NSLog(@"전면 광고 클릭됨");
}
- (void)onAdImpression:(AdropInterstitialAd *)ad {
NSLog(@"전면 광고 노출 확인됨");
}
- (void)onAdFailedToShowFullScreen:(AdropInterstitialAd *)ad :(enum AdropErrorCode)error {
NSLog(@"전면 광고 표시 실패: %ld", (long)error);
}
@endimport SwiftUI
import AdropAds
class AdropInterstitialAdWrapper: ObservableObject, AdropInterstitialAdDelegate {
@Published var isLoaded = false
@Published var errorMessage = ""
private var interstitialAd: AdropInterstitialAd?
init() {
setupInterstitialAd()
}
private func setupInterstitialAd() {
interstitialAd = AdropInterstitialAd(unitId: "PUBLIC_TEST_UNIT_ID_INTERSTITIAL")
interstitialAd?.delegate = self
}
func loadAd() {
errorMessage = ""
interstitialAd?.load()
}
func showAd() {
guard let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene,
let window = windowScene.windows.first else {
return
}
var topController = window.rootViewController
while let presentedViewController = topController?.presentedViewController {
topController = presentedViewController
}
if let topController = topController {
interstitialAd?.show(fromRootViewController: topController)
}
}
// AdropInterstitialAdDelegate
func onAdReceived(_ ad: AdropInterstitialAd) {
DispatchQueue.main.async {
self.isLoaded = true
self.errorMessage = ""
}
}
func onAdFailedToReceive(_ ad: AdropInterstitialAd, _ error: AdropErrorCode) {
DispatchQueue.main.async {
self.isLoaded = false
self.errorMessage = "로드 실패: \\(error)"
}
}
func onAdDidDismissFullScreen(_ ad: AdropInterstitialAd) {
DispatchQueue.main.async {
self.isLoaded = false
}
// 새 광고 미리 로드
loadAd()
}
func onAdFailedToShowFullScreen(_ ad: AdropInterstitialAd, _ error: AdropErrorCode) {
DispatchQueue.main.async {
self.errorMessage = "표시 실패: \\(error)"
}
}
func onAdImpression(_ ad: AdropInterstitialAd) {
print("전면 광고 노출")
}
func onAdClicked(_ ad: AdropInterstitialAd) {
print("전면 광고 클릭")
}
}
struct ContentView: View {
@StateObject var interstitialWrapper = AdropInterstitialAdWrapper()
var body: some View {
VStack(spacing: 20) {
Button("전면 광고 로드") {
interstitialWrapper.loadAd()
}
.buttonStyle(.borderedProminent)
Button("전면 광고 표시") {
interstitialWrapper.showAd()
}
.buttonStyle(.borderedProminent)
.disabled(!interstitialWrapper.isLoaded)
if interstitialWrapper.isLoaded {
Text("광고가 로드되었습니다")
.foregroundColor(.green)
}
if !interstitialWrapper.errorMessage.isEmpty {
Text(interstitialWrapper.errorMessage)
.foregroundColor(.red)
}
}
.padding()
.onAppear {
interstitialWrapper.loadAd()
}
}
}유의사항
에러 처리
func onAdFailedToReceive(_ ad: AdropPopupAd, _ error: AdropErrorCode) {
switch error {
case .ERROR_CODE_AD_NO_FILL:
print("현재 노출 가능한 팝업 광고가 없습니다")
case .ERROR_CODE_NETWORK:
print("네트워크 오류로 팝업 광고 로드 실패")
case .ERROR_CODE_INVALID_UNIT:
print("잘못된 유닛 ID입니다")
default:
print("팝업 광고 로드 실패: \(error)")
}
}적용 확인하기
console에서 발급받은 unitId가 한 번이라도 광고요청을 할 경우 성공적으로 연결됩니다.

Last updated