> 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-1/ap/ap-ios/ios-2.x.x/nam-naver-ad-manager.md).

# NAM (Naver Ad Manager)

#### NAM (Naver Ad Manager)

{% embed url="<https://naver.github.io/nam-sdk-guide/ios/>" %}

## 사용방법

{% hint style="warning" %}
**2) 초기 셋팅,  3)초기화 진행은 위 업체 링크에 들어가서 직접 설정하시는 것을 권장드립니다.**
{% endhint %}

### 1) 설치

{% content-ref url="/pages/IP2R7MXm9WlEBdvJxfnZ" %}
[iOS 2.x.x (구버전)](/ssp-sdk/undefined-1/ap/ap-ios/ios-2.x.x.md)
{% endcontent-ref %}

### 2) 초기 셋팅

**ATS(App Transport Security) 설정 ->** [**링크**](https://naver.github.io/nam-sdk-guide/ios/common/get_started#atsapp-transport-security-%EC%84%A4%EC%A0%95)[​](https://naver.github.io/nam-sdk-guide/ios/common/get_started#atsapp-transport-security-%EC%84%A4%EC%A0%95)

iOS 9부터 도입 된 App Transport Security (ATS)는 앱이 HTTPS를 통해서만 네트워크 요청을 하도록 기본설정 되어있습니다. HTTP를 사용하는 광고파트너들의 광고동작를 허용하기 위해, Info.plist 파일에 아래내용을 추가합니다.

```html
<key>NSAppTransportSecurity</key>
<dict>
    <key>NSAllowsArbitraryLoads</key>
    <true/>
</dict>
```

### 3) 초기화

**GFPAdManagerDelegate 설정** **->** [**링크**](https://naver.github.io/nam-sdk-guide/ios/common/get_started#gfpadmanagerdelegate-%EC%84%A4%EC%A0%95-%EB%B0%8F-example)

{% tabs %}
{% tab title="Objective-C" %}
NAM SDK에 ATTFramework를 통해 서비스에서 광고 추적 여부를 구현 후, `GFPAdManagerDelegate`를 통하여 Status를 SDK에 제공해줘야 합니다. 이에 아래 예시와 같이 초기화 API 및 Status를 제공해 주시기 바랍니다.

```objectivec
@import GFPSDK;
@interface AppDelegate() <APSSPSDKInitializeDelegate, GFPAdManagerDelegate>
@end

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    GFPAdConfiguration *configuration = [[GFPAdConfiguration alloc] init];
    [GFPAdManager setupWithPublisherCd:@"NAM_Publisher_cd" target:self configuration:configuration completionHandler:^(GFPError * _Nullable error) {
        NSLog(@"NAM Setup ERROR: %@", error);
    }];

}

- (GFPATTAuthorizationStatus)attStatus {
     if (@available(iOS 14.5, *)) {
        return ATTrackingManager.trackingAuthorizationStatus;
    } else {
        if ([[ASIdentifierManager sharedManager] isAdvertisingTrackingEnabled]) {
            return GFPATTAuthorizationStatusAuthorized;
        }
        
        return GFPATTAuthorizationStatusNotDetermined;
    }
}
```

{% endtab %}

{% tab title="Swift" %}
NAM SDK에 ATTFramework를 통해 서비스에서 광고 추적 여부를 구현 후, `GFPAdManagerDelegate`를 통하여 Status를 SDK에 제공해줘야 합니다. 이에 아래 예시와 같이 초기화 API 및 Status를 제공해 주시기 바랍니다.

```swift
import GFPSDK

// 1. PublisherCd 이용, GFPAdConfiguration(광고 설정) 없이 초기화 하는 경우.
GFPAdManager.setup(withPublisherCd: "publisherCd" target:self) { (error : GFPError?) in
    print("Setup Eror: \(String(describing: error?.description))")
}

// 2. PublisherCd 및 ServiceCd 이용, GFPAdConfiguration(광고 설정) 없이 초기화 하는 경우.
GFPAdManager.setup(withPublisherCd: nil, serviceCd: "serviceCd", target: self) { error in
    print("Setup Eror: \(String(describing: error?.description))")
}


func attStatus() -> GFPATTAuthorizationStatus {
    if #available(iOS 14.5, *) {
        return ATTrackingManager.trackingAuthorizationStatus
    } else {
        if ASIdentifierManager.shared().isAdvertisingTrackingEnabled {
            return .authorized
        }
        return .notDetermined
}
```

{% endtab %}
{% endtabs %}

***

## Native Layout 설정

{% hint style="warning" %}
**Adapter 내부에 들어있는 Xib 파일을 project에 꼭 넣어주세요.**
{% endhint %}

* 스토리보드에 UIView 생성 후 Custom Class을 AdPopcornSSPNativeAd 설정
* AdPopcornSSPNativeAd 변수 내부에 GfpNativeAdView, GfpNativeSimpleAdView를 포함할 수 있도록 **adAMNativeSuperView** 라는 UIView 를 생성, 추가해 줍니다. <mark style="color:red;">**(중요!)**</mark>

<figure><img src="/files/qg2twdb1bAKxmjaGWvZL" alt=""><figcaption></figcaption></figure>

NAM 은 ViewController에 ui component 영역을 바로 생성하지 않고 xib 파일을 사용하여 view를 add합니다.

GfpNativeSimpleAdView -> 따로 커스텀 하실 필요 없습니다. GfpNativeAdView -> 해당 xib 를 커스텀 하여 사용하시면 됩니다 <mark style="color:red;">**(mediaView, BodyLabel 필수!)**</mark> [NAM 참조 링크](https://naver.github.io/nam-sdk-guide/ios/native/guide_nn#%EB%84%A4%EC%9D%B4%ED%8B%B0%EB%B8%8C-%EA%B4%91%EA%B3%A0-%EB%A0%8C%EB%8D%94%EB%A7%81)

### 1) GFPNativeAdView

{% hint style="warning" %}
namNativeView를 AdPopcornNativeAd add해 주고 layout을 잡아 주어야 광고가 보입니다.
{% endhint %}

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

<pre class="language-objectivec"><code class="lang-objectivec">
<strong>#import &#x3C;AdPopcornSSP/AdPopcornSSPNativeAd.h>	
</strong>#import "NAMAdapter.h"

- (void)viewDidLoad {
    [super viewDidLoad];  
    // Size
    CGFloat width = [UIScreen mainScreen].bounds.size.width;
    CGFloat xibHeight = (width * 185) / 360;
    NSLog(@"width : %f, xibHeight : %f",width, xibHeight);
    CGFloat roundXibHeight = round(xibHeight * 10 )/ 10;
    NSLog(@"width : %f, height : %f",width, roundXibHeight);
    
    // 일반형
    GFPNativeAdView *namNativeAdView =
    [[NSBundle mainBundle] loadNibNamed:@"GFPNativeAdView" owner:nil options:nil].firstObject;
    namNativeAdView.frame = CGRectMake(0, 0, width, roundXibHeight);
    apNAMNativeAdRenderer.namNativeAdView = namNativeAdView;
    
    // 일반형을 담을 SuperView
    apNAMNativeAdRenderer.namNativeSuperView = adNAMNativeSuperView;
    
    [_adPopcornSSPNativeAd setNAMRenderer:apNAMNativeAdRenderer superView:_adNAMNativeSuperView];   // SuperView
}    
</code></pre>

{% endtab %}

{% tab title="Swift" %}

```swift
   private var namNativeView: GFPNativeAdView = GFPNativeAdView()
   private var adNAMNativeSuperView: UIView = UIView()
    
override func viewDidLoad() 
{
    super.viewDidLoad()
    // 일반형
    namNativeAdView = Bundle.main.loadNibNamed("GFPNativeAdView",
                             owner: nil,
                             options: nil)?.first as? GFPNativeAdView
    apNAMNativeAdRenderer.namNativeAdView = namNativeAdView
    apNAMNativeAdRenderer.namNativeSuperView = adNAMNativeSuperView

    adPopcornSSPNativeAd.setNAMRenderer(apNAMNativeAdRenderer, superView:adNAMNativeSuperView)  // SuperView
}

```

{% endtab %}
{% endtabs %}

NAM의 경우 AdPopcornSSP, FAN, FAN Native Banner와 다르게 xib파일을 이용하여 직접 View를 생성한 뒤, 해당 xib 파일을 읽어와 renderer에 전달해 주어야 합니다.

<mark style="color:red;">`APNAMNativeAdRenderer`</mark>에 GFPNativeAdView와 superView를 세팅 후, <mark style="color:red;">`setNAMRenderer:superView:`</mark>API를 통해 render와 adNAMNativeSuperView 를 sdk에 최종적으로 전달합니다.

(adNAMNativeSuperView 를 render 설정시 넘겨 주면 SDK내부 코드에서 광고에 맞게 nativeAd, NativeSimpIeAd 를 추가하여 제공해줍니다.)

### 2) GFPNativeSimpleAdView

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

```objectivec
#import <AdPopcornSSP/AdPopcornSSPNativeAd.h>	
#import "NAMAdapter.h"

- (void)viewDidLoad {
    [super viewDidLoad];  
    // Size
    CGFloat width = [UIScreen mainScreen].bounds.size.width;
    CGFloat xibHeight = (width * 185) / 360;
    NSLog(@"width : %f, xibHeight : %f",width, xibHeight);
    CGFloat roundXibHeight = round(xibHeight * 10 )/ 10;
    NSLog(@"width : %f, height : %f",width, roundXibHeight);
    
    // 일반형
    GFPNativeSimpleAdView *namNativeSimpleAdView =
    [[NSBundle mainBundle] loadNibNamed:@"GFPNativeSimpleAdView" owner:nil options:nil].firstObject;

    namNativeSimpleAdView.frame = CGRectMake(0, 0, width, roundXibHeight);
    apNAMNativeAdRenderer.namNativeSimpleAdView = namNativeSimpleAdView;
    
    // 일반형을 담을 SuperView
    apNAMNativeAdRenderer.namNativeSuperView = adNAMNativeSuperView;
    
    [_adPopcornSSPNativeAd setNAMRenderer:apNAMNativeAdRenderer superView:_adNAMNativeSuperView];   // SuperView
}    
```

{% endtab %}

{% tab title="Swift" %}

<pre class="language-swift"><code class="lang-swift">   private var namNativeSimpleAdView: GFPNativeSimpleAdView = GFPNativeSimpleAdView()
   private var adNAMNativeSuperView: UIView = UIView()
   
<strong>override func viewDidLoad() 
</strong>{
    super.viewDidLoad()
    namNativeSimpleAdView = Bundle.main.loadNibNamed("GFPNativeSimpleAdView",
                             owner: nil,
                             options: nil)?.first as? GFPNativeSimpleAdView
    apNAMNativeAdRenderer = APNAMNativeAdRenderer.init()
    apNAMNativeAdRenderer.namNativeSimpleAdView = namNativeSimpleAdView
    apNAMNativeAdRenderer.namNativeSuperView = adNAMNativeSuperView
    adPopcornSSPNativeAd.setNAMRenderer(apNAMNativeAdRenderer, superView:adNAMNativeSuperView)
}
</code></pre>

{% endtab %}
{% endtabs %}

NAM의 경우 AdPopcornSSP, FAN, FAN Native Banner와 다르게 xib파일을 이용하여 직접 View를 생성한 뒤, 해당 xib 파일을 읽어와 renderer에 전달해 주어야 합니다.

<mark style="color:red;">`APNAMNativeAdRenderer`</mark>에 GFPNativeAdView와 superView를 세팅 후, <mark style="color:red;">`setNAMRenderer:superView:`</mark>API를 통해 render와 adNAMNativeSuperView 를 sdk에 최종적으로 전달합니다.

(adNAMNativeSuperView 를 render 설정시 넘겨 주면 SDK내부 코드에서 광고에 맞게 nativeAd, NativeSimpIeAd 를 추가하여 제공해줍니다.)

### 3) GFPNativeAdView + GFPNativeSimpleAdView

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

```objectivec
#import <AdPopcornSSP/AdPopcornSSPNativeAd.h>	
#import "NAMAdapter.h"

- (void)viewDidLoad {
    [super viewDidLoad];  
    // Size
    CGFloat width = [UIScreen mainScreen].bounds.size.width;
    CGFloat xibHeight = (width * 185) / 360;
    NSLog(@"width : %f, xibHeight : %f",width, xibHeight);
    CGFloat roundXibHeight = round(xibHeight * 10 )/ 10;
    NSLog(@"width : %f, height : %f",width, roundXibHeight);

    // 심플형
    GFPNativeSimpleAdView *namNativeSimpleAdView =
    [[NSBundle mainBundle] loadNibNamed:@"GFPNativeSimpleAdView" owner:nil options:nil].firstObject;
    namNativeSimpleAdView.frame = CGRectMake(0, 0, width, roundXibHeight);
    APNAMNativeAdRenderer *apNAMNativeAdRenderer = [[APNAMNativeAdRenderer alloc] init];
    apNAMNativeAdRenderer.namNativeSimpleAdView = namNativeSimpleAdView;
    
    // 일반형
    GFPNativeAdView *namNativeAdView =
    [[NSBundle mainBundle] loadNibNamed:@"GFPNativeAdView" owner:nil options:nil].firstObject;
    namNativeAdView.frame = CGRectMake(0, 0, width, roundXibHeight);
    apNAMNativeAdRenderer.namNativeAdView = namNativeAdView;
    
    // 심플형 + 일반형을 담을 SuperView
    apNAMNativeAdRenderer.namNativeSuperView = adNAMNativeSuperView;
    
    [_adPopcornSSPNativeAd setNAMRenderer:apNAMNativeAdRenderer superView:_adNAMNativeSuperView];   // SuperView
}
```

{% endtab %}

{% tab title="Swift" %}

<pre class="language-swift"><code class="lang-swift">    private var namSimpleNativeView: GFPNativeSimpleAdView = GFPNativeSimpleAdView()
    private var namNativeView: GFPNativeAdView = GFPNativeAdView()
    private var adNAMNativeSuperView: UIView = UIView()

<strong>override func viewDidLoad() 
</strong>{
    super.viewDidLoad()
    // 심플형
    namNativeSimpleAdView = Bundle.main.loadNibNamed("GFPNativeSimpleAdView",
                             owner: nil,
                             options: nil)?.first as? GFPNativeSimpleAdView
    apNAMNativeAdRenderer = APNAMNativeAdRenderer.init()
    apNAMNativeAdRenderer.namNativeSimpleAdView = namNativeSimpleAdView

    // 일반형
    namNativeAdView = Bundle.main.loadNibNamed("GFPNativeAdView",
                             owner: nil,
                             options: nil)?.first as? GFPNativeAdView
    apNAMNativeAdRenderer.namNativeAdView = namNativeAdView
    apNAMNativeAdRenderer.namNativeSuperView = adNAMNativeSuperView

    adPopcornSSPNativeAd.setNAMRenderer(apNAMNativeAdRenderer, superView:adNAMNativeSuperView)  // SuperView
}
</code></pre>

{% endtab %}
{% endtabs %}

NAM의 경우 AdPopcornSSP, FAN, FAN Native Banner와 다르게 xib파일을 이용하여 직접 View를 생성한 뒤, 해당 xib 파일을 읽어와 renderer에 전달해 주어야 합니다.

<mark style="color:red;">`APNAMNativeAdRenderer`</mark>에 GFPNativeAdView와 superView를 세팅 후, <mark style="color:red;">`setNAMRenderer:superView:`</mark>API를 통해 render와 adNAMNativeSuperView 를 sdk에 최종적으로 전달합니다.

(adNAMNativeSuperView 를 render 설정시 넘겨 주면 SDK내부 코드에서 광고에 맞게 nativeAd, NativeSimpIeAd 를 추가하여 제공해줍니다.)

### GFPNativeAdView

component 별로 사용되어야 하는 타입은 아래와 같습니다.

* **필수**
  * advertiserLabel : UILabel
  * bodyLabel : UILabel
  * mediaView : GFPMediaView
  * adChoicesView : UIView<br>
* **옵션**
  * iconView : UIImageView
  * titleLabel : UILabel
  * callToActionLabel : UILabel
  * socialContextLabel : UILabel

\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~

### **+) 추가 기능**

#### **- 광고 중복 처리** <a href="#native_setting" id="native_setting"></a>

중복 제어를 관리 할 GFPAdDedupeManager 프로퍼티 선언 후 객체를 생성합니다.\
numAdsDedupe는 중복 제어 수를 의미하며, 연속된 n개의 광고에 대해 중복이 없는 광고 노출을 보장합니다. 해당 파라미터는 **2 이상 5 이하로 설정하기를 권장**합니다.(참고 : [NAM 광고 중복 처리 가이드](https://naver.github.io/nam-sdk-guide/ios/ad-dedupe/#gfpaddedupemanager-%EC%83%9D%EC%84%B1))

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

```objectivec
// 중복 처리를 위한 GFPAdDedupeManager 생성
GFPAdDedupeManager *dedupeManager = [[GFPAdDedupeManager alloc] initWithNumAdsDeduped:3];

apNAMNativeAdRenderer.namDedupeManager = dedupeManager;
```

{% endtab %}

{% tab title="Swift" %}

```swift
복 처리를 위한 GFPAdDedupeManager 생성
var dedupeManager: GFPAdDedupeManager = GFPAdDedupeManager(numAdsDeduped: 3)

apNAMNativeAdRenderer.namDedupeManager = dedupeManager
```

{% endtab %}
{% endtabs %}

#### **- 네이티브 광고 Background Blur 처리** <a href="#native_setting" id="native_setting"></a>

네이티브 광고 미디어뷰 여백의 블러처리 여부를 설정합니다. (기본값: NO) \
해당 블러처리는 섬네일 이미지가 존재할 때 적용되며, 섬네일 이미지가 존재하지 않을 경우 검은색 배경으로 노출됩니다. (참고 : [NAM Background Blur 적용 가이드](https://naver.github.io/nam-sdk-guide/ios/native-outstream/#enablemediabackgroundblur))

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

```objectivec
apNAMNativeAdRenderer.backgroundBlur = YES;   // (Defult NO)
```

{% endtab %}

{% tab title="Swift" %}

```swift
apNAMNativeAdRenderer.backgroundBlur = true   // (Defult false)
```

{% endtab %}
{% endtabs %}

#### **-** 광고 요청 타임아웃 <a href="#native_setting" id="native_setting"></a>

네이티브 광고 Timeout 시간을 설정할 수 있습니다 (참고 : [NAM TimeOut 적용 가이드](https://naver.github.io/nam-sdk-guide/ios/native-options/))

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

```objectivec
apNAMNativeAdRenderer.timeOut = 60;   // (Defult 60)
```

{% endtab %}

{% tab title="Swift" %}

```swift
apNAMNativeAdRenderer.timeOut = 60   // (Defult 60)
```

{% endtab %}
{% endtabs %}

#### **- DFP adChoicesView 위치 설정 옵션** <a href="#native_setting" id="native_setting"></a>

네이티브 광고 **adChoicesView** 위치를 설정합니다. (기본값: 오른쪽 상단) \
(참고 : [NAM adChoicesView 위치 설정  적용 가이드](https://naver.github.io/nam-sdk-guide/ios/native-outstream/#enablemediabackgroundblur))

{% tabs %}
{% tab title="Objective-C" %}
GFPAdChoicesViewPositionTopRightCorner = 1,\
GFPAdChoicesViewPositionTopLeftCorner,\
GFPAdChoicesViewPositionBottomRightCorner,\
GFPAdChoicesViewPositionBottomLeftCorner,

```objectivec
// NativeView (Defult 오른쪽 상단 코너)
apNAMNativeAdRenderer.GFPNativeSetting.preferredAdChoicesViewPosition = GFPAdChoicesViewPositionTopRightCorner;

// NativeSimpleView (Defult 오른쪽 상단 코너)
apNAMNativeAdRenderer.GFPNativeSimpleSetting.preferredAdChoicesViewPosition = GFPAdChoicesViewPositionTopRightCorner
```

{% endtab %}

{% tab title="Swift" %}
TopRightCorner,\
TopLeftCorner,\
BottomRightCorner,\
BottomLeftCorner,

```objectivec
// NativeView (Defult 오른쪽 상단 코너)
apNAMNativeAdRenderer.GFPNativeSetting.preferredAdChoicesViewPosition = GFPAdChoicesViewPositionTopRightCorner;

// NativeSimpleView (Defult 오른쪽 상단 코너)
apNAMNativeAdRenderer.GFPNativeSimpleSetting.preferredAdChoicesViewPosition = GFPAdChoicesViewPositionTopRightCorner
```

```swift
// NativeView (Defult 오른쪽 상단 코너)
apNAMNativeAdRenderer.GFPNativeSetting.preferredAdChoicesViewPosition = .TopRightCorner

// NativeSimpleView (Defult 오른쪽 상단 코너)
apNAMNativeAdRenderer.GFPNativeSimpleSetting.preferredAdChoicesViewPosition = .TopRightCorner
```

{% endtab %}
{% endtabs %}
