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

# FBAudienceNetwork (FaceBook)

#### FBAudienceNetwork

{% embed url="<https://developers.facebook.com/docs/audience-network/setting-up/platform-setup/ios/get-started?locale=ko_KR>" %}

## 사용방법

{% 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) 초기화

**->** [**링크**](https://developers.facebook.com/docs/audience-network/setting-up/platform-setup/ios/initialize-sdk)

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

```objectivec
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary<NSString *, id> *)launchOptions
{
[FBAudienceNetworkAds initializeWithSettings:nil completionHandler:nil];

// Pass user's consent after acquiring it. For sample app purposes, this is set to YES.
[FBAdSettings setAdvertiserTrackingEnabled:YES];

// Your app initialization logic goes here...

return YES;
}
```

{% endtab %}

{% tab title="Swift" %}

```swift
class AppDelegate: UIResponder {

    func setupFacebook() {
        FBAdSettings.setAdvertiserTrackingEnabled(true)
        FBAudienceNetworkAds.initialize(with: nil) { (results) in
              if results.isSuccess {
                  print("Facebook Audience Network initialized successfully")
              } else {
                  print("Failed to initialize Facebook Audience Network")
              }
        }
    }
}
```

{% endtab %}
{% endtabs %}

***

## Native Layout 설정

### 1) NativeAdView

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

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

AdPopcornSSPNativeAd 영역 안에 미디에이션 업체의 실제 광고 영역 추가 및 viewcontroller에 outlet 연결합니다.

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

{% hint style="info" %}
UI 배치와 관련한 상세한 가이드는 FAN 공식 홈페이지의 아래 주소에서 확인하시기 바랍니다.

<https://developers.facebook.com/docs/audience-network/ios-native>
{% endhint %}

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

<pre><code><strong>#import &#x3C;AdPopcornSSP/AdPopcornSSPNativeAd.h>	
</strong>#import "FANAdapter.h"

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    APFANNativeAdRenderer *apFANNativeAdRenderer = [[APFANNativeAdRenderer alloc] init];
    apFANNativeAdRenderer.adUIView = _adFANUIView;
    apFANNativeAdRenderer.adIconImageView = _adIconImageView;
    apFANNativeAdRenderer.adTitleLable = _adTitleLabel;
    apFANNativeAdRenderer.adBodyLabel = _adBodyLabel;
    apFANNativeAdRenderer.adSponsoredLabel = _sponsoredLabel;
    apFANNativeAdRenderer.adCoverMediaView = _adCoverMediaView;
    apFANNativeAdRenderer.adSocialContextLabel = _adSocialContextLabel;
    apFANNativeAdRenderer.adChoicesView = _adChoicesView;
    apFANNativeAdRenderer.adCallToActionButton = _adCallToActionButton;
    [_adPopcornSSPNativeAd setFANNativeRenderer:apFANNativeAdRenderer superView:_adFANUIView];
    }

</code></pre>

{% endtab %}

{% tab title="Swift" %}

```swift
override func viewDidLoad() 
{
    super.viewDidLoad()
    apFANNativeAdRenderer = APFANNativeAdRenderer.init()
    apFANNativeAdRenderer.adUIView = _adFANUIView
    apFANNativeAdRenderer.adIconImageView = _adIconImageView
    apFANNativeAdRenderer.adTitleLable = _adTitleLabel
    apFANNativeAdRenderer.adBodyLabel = _adBodyLabel
    apFANNativeAdRenderer.adSponsoredLabel = _sponsoredLabel
    apFANNativeAdRenderer.adCoverMediaView = _adCoverMediaView
    apFANNativeAdRenderer.adSocialContextLabel = _adSocialContextLabel
    apFANNativeAdRenderer.adChoicesView = _adChoicesView
    apFANNativeAdRenderer.adCallToActionButton = _adCallToActionButton
    adPopcornSSPNativeAd.setFANNativeRenderer(apFANNativeAdRenderer, superView: _adFANUIView)
}
```

{% endtab %}
{% endtabs %}

<mark style="color:red;">`APFANNativeAdRenderer`</mark>를 생성한 뒤, FAN 네이티브 광고에서 지원하는 ui componenet를 전달하여 준다. 단, 이 때 <mark style="color:red;">모든 UI component들은 하나의 UIView 영역 안에 포함</mark>되어 있어야 하며, 해당 superview는 adUIView 에 반드시 전달해 주어야 합니다.

{% hint style="info" %}
FANNativeAd의 경우 adCoverMediaView(FBMediaView)를 필수로 포함해야 광고가 정상적으로 노출됩니다.
{% endhint %}

APSSPNativeAdRenderer에 각 component를 세팅 후, <mark style="color:red;">`setFANNativeRenderer:superView:`</mark> API를 통해 renderer와 adUIView 를 sdk 최종적으로 전달합니다.

### 2) Banner NativeView 구성

{% file src="/files/pypEacf1aJxNzycuSZG0" %}
Sample xib 이므로 밑 **링크**에서 직접 설정 하시길 권장드립니다.
{% endfile %}

FBAudienceNetwork는 다음 링크에 들어가셔서 xib 연동한 class를 생성하셔야 합니다. **->** [**링크**](https://developers.facebook.com/docs/audience-network/setting-up/ad-setup/ios/native-banner)

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

AdPopcornSSPNativeAd 영역 안에 미디에이션 업체의 실제 광고 영역 추가 및 viewcontroller에 outlet 연결합니다.

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

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

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

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

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    APFANNativeBannerAdRenderer *apFANNativeBannerAdRenderer = [[APFANNativeBannerAdRenderer alloc] init];
    apFANNativeBannerAdRenderer.adUIView = _adFANNativeBannerUIView;
    apFANNativeBannerAdRenderer.adIconImageView = _adFANNativeBannerIconImageView;
    apFANNativeBannerAdRenderer.adSponsoredLabel = _adFANNativeBannerSponsoredLabel;
    apFANNativeBannerAdRenderer.adAdvertiserNameLabel = _adFANNativeBannerAdvertiserName;
    apFANNativeBannerAdRenderer.adChoicesView = _adFANNativeBannerChoicesView;
    apFANNativeBannerAdRenderer.adCallToActionButton = _adFANNativeBannerCTAButton;
    
    [_adPopcornSSPNativeAd setFANNativeBannerRenderer:apFANNativeBannerAdRenderer superView:_adFANNativeBannerUIView];
    }
```

<br>
{% endtab %}

{% tab title="Swift" %}

```swift
override func viewDidLoad() 
{
    super.viewDidLoad()
    apFANNativeBannerAdRenderer= APFANNativeBannerAdRenderer.init()
    apFANNativeBannerAdRenderer.adUIView = _adFANNativeBannerUIView
    apFANNativeBannerAdRenderer.adIconImageView = _adFANNativeBannerIconImageView
    apFANNativeBannerAdRenderer.adSponsoredLabel = _adFANNativeBannerSponsoredLabel
    apFANNativeBannerAdRenderer.adAdvertiserNameLabel = _adFANNativeBannerAdvertiserName
    apFANNativeBannerAdRenderer.adChoicesView = _adFANNativeBannerChoicesView
    adPopcornSSPNativeAd.setFANNativeBannerRenderer(apFANNativeBannerAdRenderer, superView: _adFANNativeBannerUIView)
}
```

{% endtab %}
{% endtabs %}

<mark style="color:red;">`APFANNativeNativeBannerAdRenderer`</mark>를 생성한 뒤, FAN 네이티브 배너 광고에서 지원하는 ui componenet를 전달하여 준다. 단, 이 때 <mark style="color:red;">모든 UI component들은 하나의 UIView 영역 안에 포함</mark>되어 있어야 하며, 해당 superview는 adUIView 에 반드시 전달해 주어야 합니다.

{% hint style="info" %}
FANNativeBannerAd의 경우 adIconImageView(FBAdIconView)를 필수로 포함해야 광고가 정상적으로 노출됩니다.
{% endhint %}

<mark style="color:red;">`APFANNativeNativeBannerAdRenderer`</mark>에 각 component를 세팅 후, setFANNativeBannerRenderer:superView:renderer와 adUIView 를 sdk 최종적으로 전달합니다.
