# AP 미디에이션(Unity iOS)

## 1. 미디에이션 Adapter 다운로드

아래 링크를 통해 iOS 미디에이션 Adapter 를 다운로드 받으세요.

[\[애드팝콘 SSP iOS Mediation UnityPlugin Adapter\]](https://github.com/IGAWorksDev/AdPopcornSDK/raw/refs/heads/master/AdPopcornSSP/02-ios-sdk/MediationAdapter_Unity/APSSPMediationAdapter_Unity_260423.zip)

## 2. 미디에이션 적용

#### 2.1 Podfile

* Unity Tool에서 iOS 빌드 후, 생성되는 Xcode 프로젝트에 아래와 같이 Podfile을 추가 합니다.

<figure><img src="/files/3ESYqaZwqGyeCy4qYmnf" alt=""><figcaption></figcaption></figure>

* PodFile 내, 사용하고자 하는 업체의 Pod 정보 입력합니다.

<pre><code>platform :ios, '14.0'

target 'UnityFramework' do
 pod 'Google-Mobile-Ads-SDK', '12.14.0'  # AdMob
 pod 'Ads-Global', '7.9.1.1'             # Pangle
 pod 'AppLovinSDK', '13.5.1'             # AppLovin
 pod 'UnityAds', '4.17.0'                # UnityAds
<strong> pod "VungleAds", '7.7.1'                # Vungle
</strong> pod 'Fyber_Marketplace_SDK', '8.4.2'    # Fyber
 
 # Meta(FAN) ==============> 수동 설치 필요 <a data-footnote-ref href="#user-content-fn-1">링크</a> (Static)
end

target 'Unity-iPhone' do
  inherit! :search_paths
end

</code></pre>

* pod update

터미널을 열고, 해당 프로젝트 폴더에서 pod update 명령을 통해 각 업체의 framework를 추가합니다.

#### **2.1-1 Meta 수동 설치 방법**

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

해당 링크에 들어가서 '**수동 다운로드'** 를 통해 framework를 다운로드 해주세요.

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

**Static Framework** Project 안에 넣어주세요.\
넣을 때 Target을 UnityFramework로 설정해주세요.

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

#### 2.2 Unity-iPhone.xcworkspace 파일로 프로젝트 오픈

Unity-iPhone.xcworkspace 파일을 통해 프로젝트를 Xcode로 open 합니다. 반드시 <mark style="color:red;">`xcworkspace`</mark>로 open 해야, pod를 통해 다운로드 한, framework가 정상적으로 추가됩니다.

#### 2.3 Adapter 파일 추가

위 다운로드 파일에서 사용하고자 하는 ap-ssp-ios-mediation-adapter > CocoaPod 폴더 안에 있는 .h, .m 파일들을 프로젝트에 추가하면 됩니다.

반드시 아래와 같이 target을 UnityFramework로 설정하여 추가합니다.

<figure><img src="/files/CoIrTVWoglpTwbf72TPT" alt="" width="563"><figcaption></figcaption></figure>

## 3. Info.plist 설정

#### 3.1 SDK Key 값 설정

Info.plist 내 Admob 사용 시에는 아래와 같이 Key 값을 추가해 주어야 합니다.

{% tabs %}
{% tab title="Admob" %}

```
<key>GADApplicationIdentifier</key>
<string>Your Admob appid</string>
```

{% endtab %}
{% endtabs %}

Unity-IPhone, UnityFramework 두곳에 모두 추가해 주셔야 합니다.

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

<figure><img src="/files/ObL9iIPMxFjvJ9iWK6wZ" alt="" width="217"><figcaption></figcaption></figure>

## 4. 미디에이션 SDK 초기화

일부 업체의 경우 앱 시작 시, 초기화 코드를 삽입하라고 안내 하고 있습니다. 이에 UnityAppController.m 파일 내 아래메소드에서 각 업체별 초기화 코드를 삽입하시기 바랍니다.

```objective-c
#import "GoogleMobileAds/GoogleMobileAds.h" // Admob
#import "AppLovinSDK/AppLovinSDK.h" // AppLovin
#import "FBAudienceNetwork/FBAudienceNetwork.h" // Meta
#import "IASDKCore/IASDKCore.h" // Fyber
#import "PAGAdSDK/PAGAdSDK.h" // Pangle
#import "VungleAdsSDK/VungleAdsSDK-Swift.h" // Vungle
#import "UnityAds/UnityAds-Swift.h" // Unity
#import "UnityAds/UnityAds.h"       // Unity

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
{
    ...
    // Admob
    [[GADMobileAds sharedInstance] startWithCompletionHandler:nil]; 
    // UnityAds
    [UnityAds initialize:@"your_game_id" testMode:NO initializationDelegate:self];
    // Vungle
    [VungleAds initWithAppId:@"app_id" completion:^(NSError * _Nullable error) {

    }];
    // AppLovin
    ALSdkInitializationConfiguration *initConfig = [ALSdkInitializationConfiguration configurationWithSdkKey:
     @"Your AppLovin Sdk Key" builderBlock:^(ALSdkInitializationConfigurationBuilder *builder) {
        builder.mediationProvider = ALMediationProviderMAX;
    }];

    // Initialize the SDK with the configuration
    [[ALSdk shared] initializeWithConfiguration: initConfig completionHandler:^(ALSdkConfiguration *sdkConfig) {
    }];
    
    // Meta
    [FBAudienceNetworkAds initializeWithSettings:nil completionHandler:nil];
    [FBAdSettings setAdvertiserTrackingEnabled:YES];
    
    // Fyber
    [[IASDKCore sharedInstance] initWithAppID:@"fyber_code"
                 completionBlock:^(BOOL success, NSError * _Nullable error) {
                   // handle result
                 }
                 completionQueue:nil];
  };
    
    // Pangle
    PAGConfig *config = [PAGConfig shareConfig];
    config.appID = @"pangle_code"; // pangle test code
    [PAGSdk startWithConfig:config completionHandler:^(BOOL success, NSError * _Nonnull error) {
        if (success) {
            //load ad data
        }
    }];
}
```

#### UnityAds SDK 초기화 설정 (주의)

```objective-c
#import "UnityAds/UnityAds-Swift.h" // Unity
#import "UnityAds/UnityAds.h"       // Unity


// 2-1. .m 파일 내부에 UnityAdsInitializationDelegate 연결 (아래 코드 직접 작성해야 함)
@interface UnityAppController () <UnityAdsInitializationDelegate> {    
}
@end

...

// 2-2. UnityAdsInitializationDelegate 연동연동으로 필수 함수 구현
@implementation UnityAppController
- (void)initializationComplete {
    
}

- (void)initializationFailed:(UnityAdsInitializationError)error withMessage:(nonnull NSString *)message {
    
}
```

## 5. 추가 설정 사항

Enmable Modules(C and Objecitve-C) 를 'Yes' 로 설정해주셔야 됩니다.

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

[^1]: <https://developers.facebook.com/docs/audience-network/setting-up/platform-setup/ios/add-sdk?locale=ko_KR>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://adpopcornssp.gitbook.io/ssp-sdk/undefined-1/ap/ap-unity-ios.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
