전면 광고
1 : 준비
프로젝트 설정을 통해 광고 연동을 위한 준비를 합니다.
2 : SDK 초기화
최초 SDK 를 초기화 완료 후, 광고 요청이 가능합니다.
사이트에서 발급받은
Media ID를 입력합니다.
import UIKit
import AdPieSDK
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
    var window: UIWindow?
    func application(_ application: UIApplication, 
        didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool 
    {
        // SDK 초기화
        AdPieSDK.sharedInstance().initWithMediaId("YOUR_MEDIA_ID")        
        return true
    }
}#import "AppDelegate.h"
#import <AdPieSDK/AdPieSDK.h>
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application 
    didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{
    // SDK 초기화
    [[AdPieSDK sharedInstance] initWithMediaId:@"YOUR_MEDIA_ID_HERE"];   
    return YES;
}
@end3 : 광고 요청
ViewController에 광고 요청을 위한 객체를 생성합니다.
사이트에서 발급받은 Slot ID를 입력합니다.
광고 요청과 표출로 메소드가 각각 나누어져 있기에, 요청을 미리하고 표출을 필요할 때 합니다.(Preload)
import UIKit
import AdPieSDK
class ViewController: UIViewController, APInterstitialDelegate {
    var interstitial: APInterstitial!
    
    override func viewDidLoad() { 
        super.viewDidLoad()
        // 광고 객체 생성 (Slot ID 입력)
        interstitial = APInterstitial(slotId: "YOUR_SLOT_ID")
        // 델리게이트 등록
        interstitial.delegate = self
        // 광고 요청
        interstitial.load()
    }
}// ViewController.h
#import <AdPieSDK/AdPieSDK.h>
@interface ViewController : UIViewController <APInterstitialDelegate>
@property APInterstitial *interstitial;
@end
// ViewController.m
@implementation ViewController
- (void)viewDidLoad {
    [super viewDidLoad];
    // 광고 객체 생성 (Slot ID 입력)
    self.interstitial = 
        [[APInterstitial alloc] initWithSlotId:@"YOUR_SLOT_ID_HERE"];
    // 델리게이트 등록
    self.interstitial.delegate = self;
    // 광고 요청
    [self.interstitial load];
}
@end4 : 광고 표출 (광고 이벤트 수신)
광고 호출에 대한 콜백을 받을 수 있습니다.
ViewController에서
APInterstitialDelegate프로토콜을 도입(adopt)합니다.광고 객체의 delegate 프로퍼티에 콜백(이벤트)를 수신받을 객체를 설정합니다.
델리게이트의 메소드 중 성공, 실패에 대한 메소드는 필수사항으로 반드시 구현해야 하며, 나머지 메소드는 필요에 따라서 구현합니다.
광고를 요청하기 위해서는
load를 호출하고, 표출하기 위해서는 swift에서는present메소드를 호출하고, Objective-C 언어에서는presentFromRootViewController:메소드를 호출합니다.에러코드를 통해 광고 실패에 대한 이유를 알 수 있습니다.
import UIKit
import AdPieSDK
class ViewController: UIViewController, APInterstitialDelegate {
    ...
        
    // MARK: - APInterstitial delegates    
    func interstitialDidLoadAd(_ interstitial: APInterstitial!) {
        // 광고 로딩 완료 후 이벤트 발생 (성공)
        
        // 광고 요청 후 즉시 노출하고자 할 경우 아래의 코드를 추가합니다.
        if interstitial.isReady() {
            // 광고 표출
            interstitial.present(fromRootViewController: self)
        }
    }
    
    func interstitialDidFail(toLoadAd interstitial: APInterstitial!, withError error: Error!) {
        // 광고 요청 실패 후 이벤트 발생
        // error code : error._code
        // error message : error.localizedDescription
    }
    
    func interstitialWillPresentScreen(_ interstitial: APInterstitial!) {
        // 광고 표출 후 이벤트 발생
    }
    
    func interstitialWillDismissScreen(_ interstitial: APInterstitial!) {
        // 광고가 표출한 뒤 종료하기 전에 이벤트 발생
    }
    
    func interstitialDidDismissScreen(_ interstitial: APInterstitial!) {
        // 광고가 표출한 뒤 종료한 후 이벤트 발생
    }
    
    func interstitialWillLeaveApplication(_ interstitial: APInterstitial!) {
        // 광고 클릭 후 이벤트 발생
    }
    
    func videoFinished(_ interstitial: APInterstitial!, videoFinishState: APVideoFinishState) {
        // 동영상 광고 종료 알림 (iOS AdPie SDK 1.6.10 지원)
        switch videoFinishState {
        case .error:
            print("동영상 광고 오류")
        case .skipped:
            print("동영상 광고 건너뜀")
        case .completed:
            print("동영상 광고 시청완료")
        default:
            break
    }
}// ViewController.m
@implementation ViewController
#pragma mark APInterstitial delegates
- (void)interstitialDidLoadAd:(APInterstitial *)interstitial {
    // 광고 로딩 완료 후 이벤트 발생 (성공)
    // 광고 요청 후 즉시 노출하고자 할 경우 아래의 코드를 추가합니다.
    if ([self.interstitial isReady]) {
        // 광고 표출
        [self.interstitial presentFromRootViewController:self];
    }
}
- (void)interstitialDidFailToLoadAd:(APInterstitial *)interstitial 
    withError:(NSError *)error 
{
    // 광고 요청 실패 후 이벤트 발생
    // error code : [error code]
    // error message : [error localizedDescription]
}
- (void)interstitialWillPresentScreen:(APInterstitial *)interstitial {
    // 광고 표출 후 이벤트 발생
}
- (void)interstitialWillDismissScreen:(APInterstitial *)interstitial {
    // 광고가 표출한 뒤 종료하기 전에 이벤트 발생
}
- (void)interstitialDidDismissScreen:(APInterstitial *)interstitial {
    // 광고가 표출한 뒤 종료한 후 이벤트 발생
}
- (void)interstitialWillLeaveApplication:(APInterstitial *)interstitial {
    // 광고 클릭 후 이벤트 발생
}
- (void)videoFinished:(APInterstitial *)interstitial videoFinishState:(APVideoFinishState)finishState {
    // 동영상 광고 종료 알림 (iOS AdPie SDK 1.6.10 지원)
    switch (videoFinishState) {
        case APVideoFinishStateError:       break;  // 동영상 광고 오류
        case APVideoFinishStateCompleted:   break;  // 동영상 광고 건너띔
        case APVideoFinishStateSkipped:     break;  // 동영상 광고 시청완료
        default:
            break;
    }
}
@endLast updated