> 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/adfit.md).

# AdFit

#### AdFit&#x20;

{% embed url="<https://adfit.github.io/adfit-ios-sdk/documentation/adfitsdk>" %}

## 사용방법

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

### 1) 설치

{% hint style="danger" %}
**'AdFit'  '**<mark style="color:red;">**3.18.3**</mark>**' 이후 ver 부터는&#x20;**<mark style="color:red;">**SPM(Swift Package Manager)에서만 제공**</mark>**됩니다.**
{% endhint %}

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

### 2) 초기 셋팅

**SKAdNetwork 설정 ->** [**링크**](https://adfit.github.io/adfit-ios-sdk/documentation/adfitsdk/skadnetwork)\
&#x20;다음 코드를 사용하여 Info.plist의 SKAdNetworkItems을 직접 추가해 주시고 다음 값들을 넣어 주세요.

<details>

<summary><strong>SKAdNetwork</strong></summary>

```
<key>SKAdNetworkItems</key>
<array>
    <dict>
        <key>SKAdNetworkIdentifier</key>
        <string>9t245vhmpl.skadnetwork</string>
    </dict>
    <dict>
        <key>SKAdNetworkIdentifier</key>
        <string>v72qych5uu.skadnetwork</string>
    </dict>
    <dict>
        <key>SKAdNetworkIdentifier</key>
        <string>x8uqf25wch.skadnetwork</string>
    </dict>
    <dict>
        <key>SKAdNetworkIdentifier</key>
        <string>8s468mfl3y.skadnetwork</string>
    </dict>
    <dict>
        <key>SKAdNetworkIdentifier</key>
        <string>54NZKQM89Y.skadnetwork</string>
    </dict>
    <dict>
        <key>SKAdNetworkIdentifier</key>
        <string>t6d3zquu66.skadnetwork</string>
    </dict>
</array>
```

</details>

**ATS(App Transport Security) 설정 ->** [**링크**](https://adfit.github.io/adfit-ios-sdk/documentation/adfitsdk/ats)[​](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>
```

***

## Native Layout 설정

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

### 1) NativeAdView

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

AdFitNativeAdView XIB 파일을 load해 주고\
APSSPAdFitNativeAdRenderable, AdFitNativeAdView 변수에 할당해 줍니다.

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

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

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

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    APSSPAdfitNativeAdView *adfitNativeAd =
    [[NSBundle mainBundle] loadNibNamed:@"APSSPAdfitNativeAdView" owner:nil options:nil].firstObject;
    adfitNativeAd.frame = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 250);
    
    APAdFitNativeAdRenderer *apAdFitNativeAdRenderer = [[APAdFitNativeAdRenderer alloc] init];
    apAdFitNativeAdRenderer.useBizBoardTemplate = NO;
    apAdFitNativeAdRenderer.adfitNativeAdUIView = adfitNativeAd;
    [_adPopcornSSPNativeAd setAdFitRenderer:apAdFitNativeAdRenderer superView:adfitNativeAd];
}
```

{% endtab %}

{% tab title="Swift" %}

```swift
override func viewDidLoad() 
{
    super.viewDidLoad()
    adfitNativeAd = Bundle.main.loadNibNamed("APSSPAdfitNativeAdView",
                             owner: nil,
                             options: nil)?.first as? APSSPAdfitNativeAdView
    adfitNativeAd.frame = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 250)                         
    
    apAdFitNativeAdRenderer= APAdFitNativeAdRenderer.init()
    apAdFitNativeAdRenderer.useBizBoardTemplate = false
    apAdFitNativeAdRenderer.adfitNativeAdUIView = adfitNativeAd
    adPopcornSSPNativeAd.setAdFitRenderer(apAdFitNativeAdRenderer, superView: adfitNativeAd)
}
```

{% endtab %}
{% endtabs %}

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

`APAdFitNativeAdRenderer`에 adfitNativeAdUIView 와 superView를 세팅 후, `setAdFitRenderer:superView:` API를 통해 render와 APSSPAdfitNativeAdView 를 sdk에 최종적으로 전달.

{% hint style="danger" %}
반드시 <mark style="color:red;">**useBizBoardTemplate**</mark>을 <mark style="color:red;">**No**</mark>로 설정해야 합니다.
{% endhint %}

### 2) BizBoard

AdFit-Bizboard 는 코드 상 BizBoardTemplate을 생성하여, 연동을 진행하면 됩니다.

AdFit BizBoardTemplate 사용 시 아래와 같이 연동을 진행하면 됩니다.

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

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

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

- (void)viewDidLoad
{	
    [super viewDidLoad];	
    APAdFitNativeAdRenderer *apAdFitNativeAdRenderer = [[APAdFitNativeAdRenderer alloc] init];
    BizBoardTemplate *bizBoardTemplate = [[BizBoardTemplate alloc] init];
    apAdFitNativeAdRenderer.adfitBizBoardTemplate = bizBoardTemplate;
    apAdFitNativeAdRenderer.bizBoardInfoIconRightConstant = -16; (물음표 아이콘 커스터마이징)
    [_adPopcornSSPNativeAd setAdFitRenderer:apAdFitNativeAdRenderer superView:bizBoardTemplate];
}
```

{% endtab %}

{% tab title="Swift" %}

```swift
override func viewDidLoad() 
{
    super.viewDidLoad()
    apAdFitNativeAdRenderer = APAdFitNativeAdRenderer.init()
    let apAdFitNativeAdRenderer = APAdFitNativeAdRenderer.init()
    let bizBoardTemplate = BizBoardTemplate()
    apAdFitNativeAdRenderer.adfitBizBoardTemplate = bizBoardTemplate
    adPopcornSSPNativeAd.setAdFitRenderer(apAdFitNativeAdRenderer, superView: bizBoardTemplate)
}
```

{% endtab %}
{% endtabs %}

<mark style="color:red;">`APAdFitNativeAdRenderer`</mark>에 BizBoardTemplate을 설정 한 뒤, <mark style="color:red;">`setAdFitRenderer`</mark>API를 통해 render와 bizBoardTemplateView(superView)를 세팅합니다.

{% hint style="info" %}
우측 상단의 물음표 아이콘의 경우 APAdFitNativeAdRenderer의 아래 property를 통해 위치 조정이 가능합니다.

* bizBoardInfoIconTopConstant
* bizBoardInfoIconBottomConstant
* bizBoardInfoIconLeftConstant
* bizBoardInfoIconRightConstant
  {% endhint %}
