iOS 전면 광고

1

Unit ID 설정하기

Ad type
Ad unit ID

Interstitial

PUBLIC_TEST_UNIT_ID_INTERSTITIAL

2

필요한 파라미터 정의

struct AdropUnitId {
    // 전면 광고 유닛 ID (실제 발급받은 ID로 교체)
    static let INTERSTITIAL_IMAGE = "YOUR_INTERSTITIAL_UNIT_ID"
}
3

전면 광고 구현

import AdropAds

class ViewController: UIViewController {
    private var interstitialAd: AdropInterstitialAd?
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        // 전면 광고 로드
        loadInterstitialAd()
        
        // 버튼 클릭 시 광고 표시
        setupShowButton()
    }
    
    private func loadInterstitialAd() {
        interstitialAd = AdropInterstitialAd(unitId: AdropUnitId.INTERSTITIAL_IMAGE)
        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)")
    }
}

Last updated