> ## 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 的 AppsFlyer 广告收入连接器。无需发布方编写胶水代码即可将 CloudX 广告收入转发至 AppsFlyer。

连接器（Connector）用于在 CloudX SDK 与其他产品之间传递数据。AppsFlyer 连接器会将 CloudX 广告收入转发至您的移动归因合作伙伴（MMP），使广告收入与您在 AppsFlyer 中的其他数据一并呈现。只需添加依赖，收入上报即自动生效——连接器会在加载时向 CloudX SDK 自行注册，加入与 `CloudXCore.addAdRevenueDelegate(_:)` 相同的全局广告收入委托列表。

## 安装

### CocoaPods

```ruby Podfile theme={null}
pod 'CloudXAppsFlyerConnector', '~> 6.15.0.0'
```

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

无需任何代码改动。连接器不会初始化 AppsFlyer，它使用您现有的 AppsFlyer 配置和 dev key。

### 手动注册

该 pod 会为您的 target 设置 `-ObjC`，以确保连接器的 `+load` 在宿主应用中执行并完成自行注册。如果您的构建未使用 `-ObjC` 链接，请在初始化 CloudX SDK 之前或之后手动注册一次：

<CodeGroup>
  ```objc Objective-C theme={null}
  #import <CloudXAppsFlyerConnector/CloudXAppsFlyerConnector.h>

  CloudXAppsFlyerConnectorRegister();
  ```

  ```swift Swift theme={null}
  CloudXAppsFlyerConnectorRegister()
  ```
</CodeGroup>

## 要求

* CloudXCore `3.6.0` 或更高版本——这是首个提供连接器所依附的全局广告收入委托 API 的版本。
* 您的应用已使用自己的 dev key 集成并初始化 AppsFlyer SDK。连接器不会打包或初始化 AppsFlyer；CocoaPods 会将该依赖与您应用中已有的 `AppsFlyerFramework` 去重，因此运行时使用的是您的版本。
* 受支持的 AppsFlyer SDK 版本：`AppsFlyerFramework` `6.15.0` 或更高版本。没有上限——AppsFlyer 的集成式广告收入 API 在 6.15+ 与 7.x 系列中保持稳定。

## 上报内容

连接器会为每次 CloudX 竞得的展示调用一次 AppsFlyer 的 `logAdRevenue`，覆盖所有 CloudX 广告格式——banner、MREC、interstitial、rewarded、native 和 app open。每次调用会携带竞得的广告网络、该次展示的 CloudX 收入估算（USD）以及 CloudX 广告单元、格式和广告位。

<Warning>
  如果您的应用已在 CloudX 广告收入委托中调用 `AppsFlyerLib.shared().logAdRevenue`，请在添加本连接器时移除该代码，否则每次展示都会向 AppsFlyer 重复上报两次。
</Warning>

## 兼容性

| 连接器版本      | AppsFlyer SDK                    | 最低 CloudXCore |
| ---------- | -------------------------------- | ------------- |
| `6.15.0.0` | `AppsFlyerFramework` `>= 6.15.0` | `3.6.0`       |

## 自行上报收入

如果您希望自行控制上报调用，可以不使用连接器，直接注册自己的广告收入委托：

<CodeGroup>
  ```swift Swift theme={null}
  final class MyAdRevenueDelegate: NSObject, CLXAdRevenueDelegate {
      func didPayRevenue(for ad: CLXAd) {
          // 使用您自己的字段映射转发至 AppsFlyer 或任何其他目标。
      }
  }

  CloudXCore.addAdRevenueDelegate(myAdRevenueDelegate)
  ```

  ```objc Objective-C theme={null}
  [CloudXCore addAdRevenueDelegate:myAdRevenueDelegate];
  ```
</CodeGroup>

`+[CloudXCore addAdRevenueDelegate:]` 是稳定的公开接口，`removeAdRevenueDelegate:` 用于取消注册。请只选择连接器或自行注册委托其中一种方式，不要同时使用。

## 支持

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