> ## Documentation Index
> Fetch the complete documentation index at: https://docs.cloudx.io/llms.txt
> Use this file to discover all available pages before exploring further.

# 集成

> CloudX iOS SDK 的 Meta Audience Network 适配器。支持 Banner、MREC、Interstitial、Rewarded 和 Native。

有关 CloudX 控制台映射和 Meta 侧 ID 设置，请参阅 [Meta Audience Network 竞价方指南](/zh/networks/meta-audience-network)。本页仅说明 iOS 特定的集成细节。

## 安装

### CocoaPods

```ruby Podfile theme={null}
pod 'CloudXMetaAdapter', '~> 6.21.1.0'
```

```bash theme={null}
pod install --repo-update
```

### 手动安装

1. 从 [Releases](https://github.com/cloudx-io/cloudx-ios/releases) 下载 `CloudXMetaAdapter.xcframework.zip`
2. 解压并将 `CloudXMetaAdapter.xcframework` 拖入您的 Xcode 项目
3. 手动添加 `FBAudienceNetwork`（`= 6.21.1`）。

## Info.plist 配置

### SKAdNetwork IDs（iOS 14.5+ 必需）

Meta 进行竞价需要两个 Meta SKAdNetwork ID：

```xml Info.plist theme={null}
<key>SKAdNetworkItems</key>
<array>
    <dict>
        <key>SKAdNetworkIdentifier</key>
        <string>v9wttpbfk9.skadnetwork</string>
    </dict>
    <dict>
        <key>SKAdNetworkIdentifier</key>
        <string>n38lu8286q.skadnetwork</string>
    </dict>
</array>
```

### 应用追踪透明度（iOS 14+）

```xml Info.plist theme={null}
<key>NSUserTrackingUsageDescription</key>
<string>此标识符将用于向您投放个性化广告。</string>
```

## 项目配置

**链接器标志：** 在 Build Settings 中将 `-ObjC` 添加到 Other Linker Flags。

**Bitcode：** Meta SDK 不支持 Bitcode。将 Enable Bitcode 设置为 `NO`。

## Meta SDK 6.21.0 SceneDelegate 崩溃问题

<Warning>
  Meta Audience Network SDK 6.21.0 存在一个内部 bug，在使用 `SceneDelegate`（iOS 13+ 基于场景的生命周期）的应用中会导致崩溃。
</Warning>

### 问题描述

崩溃发生在横幅广告展示期间，错误信息如下：

```
*** -[NSProxy doesNotRecognizeSelector:observeScreenOrientationChanges:] called!
```

这是一个 **Meta SDK 内部 bug**，其 `FBDisplayAdController` 创建的 `NSProxy` 未正确配置方向观察。

### 解决方案：移除 SceneDelegate

**唯一可靠的修复方案**是使用旧式的仅 `AppDelegate` 模式（不使用 `SceneDelegate`）。

#### 步骤 1：移除 SceneDelegate 文件

从项目中删除 `SceneDelegate.h` 和 `SceneDelegate.m`。

#### 步骤 2：从 Info.plist 中移除 UIApplicationSceneManifest

从 `Info.plist` 中移除整个 `UIApplicationSceneManifest` 部分。

#### 步骤 3：向 Info.plist 添加必需的键

```xml Info.plist theme={null}
<key>UIMainStoryboardFile</key>
<string>Main</string>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
```

#### 步骤 4：更新 AppDelegate

<CodeGroup>
  ```objc Objective-C theme={null}
  // AppDelegate.h
  @interface AppDelegate : UIResponder <UIApplicationDelegate>
  @property (strong, nonatomic) UIWindow *window;
  @end

  // AppDelegate.m
  - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
      self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
      self.window.rootViewController = [[YourRootViewController alloc] init];
      [self.window makeKeyAndVisible];
      return YES;
  }
  ```

  ```swift Swift theme={null}
  class AppDelegate: UIResponder, UIApplicationDelegate {
      var window: UIWindow?

      func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
          window = UIWindow(frame: UIScreen.main.bounds)
          window?.rootViewController = YourRootViewController()
          window?.makeKeyAndVisible()
          return true
      }
  }
  ```
</CodeGroup>

### Xcode 警告

移除 SceneDelegate 后，您会看到以下警告：

```
CLIENT OF UIKIT REQUIRES UPDATE: This process does not adopt UIScene lifecycle.
```

此警告是**预期行为**，不会影响功能。

## 兼容性

| 适配器版本      | 广告网络 SDK                       | 最低 CloudXCore |
| ---------- | ------------------------------ | ------------- |
| `6.21.1.0` | Meta Audience Network `6.21.1` | `3.5.0`       |

当服务端下发的 CloudX 配置包含该广告网络需求时，SDK 会自动发现该适配器。无需手动注册适配器。

## 支持

如需支持，请联系 [mobile@cloudx.io](mailto:mobile@cloudx.io)
