> For the complete documentation index, see [llms.txt](https://adpopcornssp.gitbook.io/ssp-sdk/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://adpopcornssp.gitbook.io/ssp-sdk/undefined-2/extra-guide/undefined-3/ios.md).

# 커스텀 타입(iOS)

아래 가이드에는 커스텀 타입 광고 타입에 대해 설명 하고 있으며, 기본적인 연동은 애드팝콘 SSP 정식 가이드 사이트에서 확인하시기 바랍니다.

<details>

<summary>커스텀 광고?</summary>

SDK를 통해 자동으로 광고를 노출하지 않고 광고 노출에 필요한 정보를 받아 직접 광고를 노출 시켜주는 수동 광고 타입

</details>

## 1. 기본 연동

[애드팝콘 SSP SDK iOS 기본 설정](/ssp-sdk/sdk/ios/ios-2.x.x/undefined.md)을 참고하시고 아래 사항 SSP SDK 기본 연동 진행이 필요합니다.

* SDK 다운로드 및 설치
* 코드 연동

## 2. 인스턴스 생성

커스텀 광고를 요청하기 위해 인스턴스 생성 및 추가합니다.

{% tabs %}
{% tab title="Objective-C" %}
광고를 노출하고자 하는 <mark style="color:red;">`ViewController.m`</mark> 을 수정하여 <mark style="color:red;">`AdPopcornSSPCustomAd.h`</mark>를 import 하여 <mark style="color:red;">`AdPopcornSSPCustomAd`</mark> 인스턴스 변수를 생성합니다.

```swift
#import <AdPopcornSSP/AdPopcornSSPCustomAd.h>

@interface AdPopcornSSPCustomAdViewController () <APSSPCustomAdDelegate> 
{	
	AdPopcornSSPCustomAd *_customAd;
}

@end

@implementation AdPopcornSSPCustomAdViewController 

	- (void)viewDidLoad { 
		[super viewDidLoad]; 		
		_customAd = [[AdPopcornSSPCustomAd alloc] initWithAppKey:@"YOUR_APP_KEY"
		    placementId:@"YOUR_PLACEMENT_ID" adType:SSPCustomAdNativeAd];			
	}

@end
```

{% endtab %}

{% tab title="Swift" %}
아래 코드와 같이 SSP 사업팀으로부터 전달 받은 <mark style="color:red;">`AppKey`</mark>, <mark style="color:red;">`placementId`</mark>를 이용해 커스텀 광고 인스턴스를 생성합니다.

```swift
Class ViewController : UIViewController, APSSPCustomAdDelegate
{
	var customAd: AdPopcornSSPCustomAd!
	override func viewDidLoad() {
		customAd = AdPopcornSSPCustomAd.init(appKey: "YOUR_APP_KEY",
			placementId: "YOUR_PLACEMENT_ID", adType: SSPCustomAdNativeAd);
		}
}
```

{% endtab %}
{% endtabs %}

커스텀 광고 인스턴스 생성 시, appKey, placementId, adType을 넘겨주어야 하며 지원 하는 adType은 아래와 같습니다.

| adType                  | 설명                |
| ----------------------- | ----------------- |
| SSPCustomAd320x50       | 배너 광고 320x50 사이즈  |
| SSPCustomAd300x250      | 배너 광고 300x250 사이즈 |
| SSPCustomAd320x100      | 배너 광고 320x100 사이즈 |
| SSPCustomAdInterstitial | 전면 광고             |
| SSPCustomAdNativeAd     | 네이티브 광고           |

## 3. 델리게이트 설정

커스텀 광고 요청에 대한 결과를 전달 받을 delegate를 설정합니다.

{% tabs %}
{% tab title="Objective-C" %}

<table><thead><tr><th width="284">delegate</th><th>설명</th></tr></thead><tbody><tr><td>APSSPCustomAdLoadSuccess</td><td>광고 요청에 성공한 경우. adData에 광고 정보가 넘어옵니다.</td></tr><tr><td>APSSPCustomAdLoadFail</td><td>광고 요청에 실패한 경우</td></tr></tbody></table>

```objectivec
#import <AdPopcornSSP/AdPopcornSSPCustomAd.h>

@interface AdPopcornSSPCustomAdViewController () <APSSPCustomAdDelegate> 
{	
	AdPopcornSSPCustomAd *_customAd;
}

@end

@implementation AdPopcornSSPCustomAdViewController 

	- (void)viewDidLoad { 
		[super viewDidLoad]; 		
		_customAd = [[AdPopcornSSPCustomAd alloc] initWithAppKey:@"YOUR_APP_KEY"
			 placementId:@"YOUR_PLACEMENT_ID" adType:SSPCustomAdNativeAd];
		_customAd.delegate = self;
	}
	
	#pragma mark - APSSPCustomAdDelegate
	- (void)APSSPCustomAdLoadSuccess:(AdPopcornSSPCustomAd *)customAd adData:(NSString *)adData
	{
		  NSLog(@"APSSPCustomAdLoadSuccess : %@", adData);
		  if(_customAd != nil)
		  {
					// 네이티브 타입
			    NSData *jsonData = [adData dataUsingEncoding:NSUTF8StringEncoding];
			    id json = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:nil];
			    NSString *title = [json valueForKey:@"Title"];
			    NSString *landingURL = [json valueForKey:@"LandingURL"];
		  }
	}

	- (void)APSSPCustomAdLoadFail:(AdPopcornSSPCustomAd *)customAd error:(AdPopcornSSPError *)error
	{
		  NSLog(@"APSSPCustomAdLoadFail : %@", error);
	}
@end
```

{% endtab %}

{% tab title="Swift" %}

<table><thead><tr><th width="283">delegate</th><th>설명</th></tr></thead><tbody><tr><td>apsspCustomAdLoadSuccess</td><td>광고 요청에 성공한 경우. adData에 광고 정보가 넘어옵니다.</td></tr><tr><td>apsspCustomAdLoadFail</td><td>광고 요청에 실패한 경우</td></tr></tbody></table>

```swift
class ViewController: UIViewController, APSSPCustomAdDelegate
{	
	var customAd: AdPopcornSSPCustomAd!
	override func viewDidLoad() {
		customAd = AdPopcornSSPCustomAd.init(appKey: "YOUR_APP_KEY",
		placementId: "YOUR_PLACEMENT_ID", adType: SSPCustomAdNativeAd);
		customAd.delegate = self;
	}

	// CustomAd Delegate
	func apsspCustomAdLoadSuccess(_ customAd: AdPopcornSSPCustomAd!, adData:String!) {
				
	}
	func apsspCustomAdLoadFail(_ customAd: AdPopcornSSPCustomAd!, error: AdPopcornSSPError!) {
				
	}
}
```

{% endtab %}
{% endtabs %}

* 각 광고 타입별 성공 시 adData 예시는 아래와 같습니다.

{% tabs %}
{% tab title="200: adData 예시 - 배너, 전면" %}

```html
<html><head><style>html,body{overflow:hidden;position:relative;width:100%;heigh
t:100%;margin:0;padding:0}</style></head>><body>
<a href="https://partners.igaworks.com/"target="_blank">
<img src="https://adpopcorn-ssp/test_campaign/300x250.JPG" width="300"
height="250" /></a></body></html><style>
html,body{overflow:hidden;position:relative;width:100%;height:100%;margin:0;paddin
g:0}</style>
```

{% endtab %}

{% tab title="200: adData 예시 - 네이티브" %}

```json
{
	 CtaText = “Click";
	 Desc = “Adpopcorn SSP description sample”;
	 IconImageURL = “https://static.adbrix.igaworks.com/adpopcornssp/test_campaign/80x80_icon.jpg”;
	 MainImageURL = “https://static.adbrix.igaworks.com/adpopcornssp/test_campaign/1200x627.jpg”;
	 PrivacyPolicyImageURL = “https://static.adbrix.igaworks.com/adpopcornssp/default_image/warning.png”;
	 PrivacyPolicyURL = “https://www.igaworks.com/ko/rule_user.html”;
	 Title = “Title sample”;
	 LandingURL = “https://www.igaworks.com”;
}
```

{% endtab %}
{% endtabs %}

## 4. 광고 요청

광고 요청 시점에 <mark style="color:red;">`load`</mark> API 호출하여 서버에 광고를 요청합니다.

{% tabs %}
{% tab title="Objective-C" %}

```objectivec
#import <AdPopcornSSP/AdPopcornSSPCustomAd.h>

@interface AdPopcornSSPCustomAdViewController () <APSSPCustomAdDelegate> 
{	
	AdPopcornSSPCustomAd *_customAd;
}

@end
@implementation AdPopcornSSPCustomAdViewController 

	- (void)viewDidLoad { 
		[super viewDidLoad]; 		
		_customAd = [[AdPopcornSSPCustomAd alloc] initWithAppKey:@"YOUR_APP_KEY"
			 placementId:@"YOUR_PLACEMENT_ID" adType:SSPCustomAdNativeAd];
		_customAd.delegate = self;
		[_customAd loadAd];
	}
	
	#pragma mark - APSSPCustomAdDelegate
	- (void)APSSPCustomAdLoadSuccess:(AdPopcornSSPCustomAd *)customAd adData:(NSString *)adData
	{
		  NSLog(@"APSSPCustomAdLoadSuccess : %@", adData);
		  if(_customAd != nil)
		  {
					// 네이티브 타입
			    NSData *jsonData = [adData dataUsingEncoding:NSUTF8StringEncoding];
			    id json = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:nil];
			    NSString *title = [json valueForKey:@"Title"];
			    NSString *landingURL = [json valueForKey:@"LandingURL"];
		  }
	}

	- (void)APSSPCustomAdLoadFail:(AdPopcornSSPCustomAd *)customAd error:(AdPopcornSSPError *)error
	{
		  NSLog(@"APSSPCustomAdLoadFail : %@", error);
	}
@end
```

{% endtab %}

{% tab title="Swift" %}

```swift
customAd.load()
```

{% endtab %}
{% endtabs %}

## 5. 광고 노출, 클릭 리포트 수집

커스텀 광고 타입의 경우 매체가 직접 광고물을 노출시키고, 클릭 처리를 해주어야 하기에 <mark style="color:red;">반드시 아래 두 API를 적절한 시점해 호출해 주는 연동을 진행해 주어야 정확한 데이터 수집이 가능</mark>합니다.

{% tabs %}
{% tab title="Objective-C" %}

```swift
// 광고 노출 시점에 호출
[_customAd reportImpression];
    
// 광고 클릭 시점에 호출
[_customAd reportClick];
```

{% endtab %}

{% tab title="Swift" %}

```swift
// 광고 노출 시점에 호출
customAd.reportImpression();

// 광고 클릭 시점에 호출
customAd.reportClick();
```

{% endtab %}
{% endtabs %}

위 연동 중 궁금하신 사항이나 수정이 필요한 부분이 있으면 애드팝콘 사업팀(<pm@adpopcorn.com>)으로 메일 주시기 바랍니다.
