AdPie
  • AdPie
    • 시작하기
  • Android
    • 프로젝트 설정
    • 광고 연동
      • 배너 광고
      • 전면 광고
      • 네이티브 광고
      • 리워드 비디오 광고
    • 미디에이션
      • 구글 애드몹
      • 구글 애드 매니저
      • 앱러빈
    • 공통
      • 에러코드
      • 디버깅
    • 변경내역
  • iOS
    • 프로젝트 설정
    • iOS 14+ 대응
    • 광고 연동
      • 배너 광고
      • 전면 광고
      • 네이티브 광고
      • 리워드 비디오 광고
    • 미디에이션
      • 구글 애드몹
      • 구글 애드 매니저
      • 앱러빈
    • 공통
      • 에러코드
      • 디버깅
      • 타겟팅
    • 변경내역
  • Flutter
    • 프로젝트 설정
    • 광고 연동
      • 배너 광고
      • 전면 광고
      • 리워드 비디오 광고
    • 공통
      • 에러코드
    • 변경내역
  • Unity
    • 프로젝트 설정
    • 광고 연동
      • 배너 광고
      • 전면 광고
      • 리워드 비디오 광고
    • 공통
      • 에러코드
    • 변경내역
  • Exchange
    • For Buyers
Powered by GitBook
On this page
  • 1 : 준비
  • 2 : SDK 초기화
  • 3 : 광고 요청
  • 4 : 광고 표출 (광고 이벤트 수신)
  1. iOS
  2. 광고 연동

전면 광고

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;
}

@end

3 : 광고 요청

  • 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];
}

@end

4 : 광고 표출 (광고 이벤트 수신)

  • 광고 호출에 대한 콜백을 받을 수 있다.

  • 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!) {
        // 광고 클릭 후 이벤트 발생
    }
}
// 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 {
    // 광고 클릭 후 이벤트 발생
}

@end
Previous배너 광고Next네이티브 광고

Last updated 8 months ago