SDK接入配置
1. 聚合SDK导入
- 选择需要接入的第三方广告网络,创建应用并拿到聚合SDK所需的参数,详细信息可查看【第三方广告网络操作指南】
- 聚合SDK依赖于ToBid广告SDK,故使用前必须集成广告SDK。否则,可能会有编译不通过等问题。
- 可下载我们提供的ToBid聚合示例Demo,查看完整的接入代码【点击查看】
1.1. framework直接导入
获取相应版本的framework库,导入项目工程即可。
必须导入的库:
WindFoundation.xcframework
WindSDK.xcframework
WindMillSDK.xcframework
三方SDK根据需要,导入对应的SDK和适配器即可。详细请查看【第三方广告网络配置说明】
1.2. cocoapod引入
在podfile文件中添加:
#核心库,必须添加
pod 'ToBid-iOS'
# 各平台的Adapter和sdk根据需要自行选择导入,参考下方PodCode| Network | Pod Code | 渠道支持最低系统 |
|---|---|---|
| ToBid | pod 'ToBid-iOS' | 11.0 |
| Admob | pod 'ToBid-iOS/AdmobAdapter' | 12.0 |
| AppLovin | pod 'ToBid-iOS/AppLovinAdapter' | 12.0 |
| 百度 | pod 'ToBid-iOS/BaiduAdapter' | 11.0 |
| 穿山甲 | pod 'ToBid-iOS/CSJAdapter' | 11.0 |
| 腾讯优量汇 | pod 'ToBid-iOS/GDTAdapter' | 11.0 |
| Gromore | pod 'ToBid-iOS/GromoreAdapter' | 11.0 |
| IronSource | pod 'ToBid-iOS/IronSourceAdapter' | 12.0 |
| 快手 | pod 'ToBid-iOS/KSAdapter' | 11.0 |
| Mintegral | pod 'ToBid-iOS/MintegralAdapter' | 11.0 |
| UnityAds | pod 'ToBid-iOS/UnityAdsAdapter' | 13.0 |
| Vungle | pod 'ToBid-iOS/VungleAdapter' | 12.0 |
| Adscope | pod 'ToBid-iOS/AdScopeAdapter' | 11.0 |
| 美数 | pod 'ToBid-iOS/MSAdAdapter' | 11.0 |
| 趣盟 | pod 'ToBid-iOS/QuMengAdapter' | 11.0 |
| 京媒 | pod 'ToBid-iOS/JADYunAdapter' | 11.0 |
| 倍业 | pod 'ToBid-iOS/MercuryAdapter' | 11.0 |
| 章鱼 | pod 'ToBid-iOS/OctopusAdapter' | 11.0 |
| 旺脉 | pod 'ToBid-iOS/WangMaiAdapter' | 11.0 |
| 聚推 | pod 'ToBid-iOS/JuTuiAdapter' | 11.0 |
| 泛为 | pod 'ToBid-iOS/PTGAdapter' | 11.0 |
| 酷盈 | pod 'ToBid-iOS/KuyingAdapter' | 10.0 |
| 布鲁肯 | pod 'ToBid-iOS/BulukenAdapter' | 13.0 |
| 自定义竞价回传插件 | pod 'ToBid-iOS/BidResultAdapter' | 11.0 |
当导入某个适配器时,会自动通过pod下载对应渠道的SDK,由于Adapter和第三方广告SDK会存在版本兼容问题,所以我们建议通过pod Adapter的方式去依赖第三方广告SDK来确保不会有任何的版本兼容问题。
如果您想要引入特定版本的SDK则需要在pod 语句后面添加版本号(以1.0.0版本为例)、例如: pod 'ToBid-iOS', '1.5.0'
2. Xcode编译选项设置
2.1. Other Linker Flags
在Xcode中选择项目的Targets->Build Settings,配置Other Linker Flags 增加 -ObjC。
2.2. 添加HTTP权限
- 工程plist文件设置,点击右边的information Property List后边的 "+" 展开
添加 App Transport Security Settings,先点击左侧展开箭头,再点右侧加号,Allow Arbitrary Loads 选项自动加入,修改值为 YES。 SDK API 已经全部支持HTTPS,但是广告主素材存在非HTTPS情况。
注意:Allow Arbitrary Loads in Web Content key存在时会忽略Allow Arbitrary Loads的设置(iOS10之后)
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>2.3. 添加定位权限
该权限非必须,sdk不包含任何请求定位权限的代码,也不会主动请求定位权限。
工程info.plist文件设置,点击右边的information Property List后边的 "+" 展开 添加Privacy - Location When In Use Usage Description。
2.4. 运行环境配置
- 支持系统 iOS 11.0 及以上;
- SDK编译环境 Xcode 16.0 + ;
- 支持架构:真机 arm64;模拟器 arm64、x86_64(5.10.2 起,详见 2.6)
2.5. 添加依赖库
工程需要在TARGETS -> Build Phases中找到Link Binary With Libraries,点击“+”,依次添加下列依赖库
- CoreML.framework (SDK4.0.0及以上版本新增,穿山甲/Gromore6.3.0.0及以上版本新增)
以下是TOBID需要的库,手动集成还需参考添加的渠道需要的依赖库。
- libc++abi.tbd
- StoreKit.framework
- CFNetwork.framework
- CoreMedia.framework
- AdSupport.framework
- CoreMotion.framework
- MediaPlayer.framework
- CoreGraphics.framework
- AVFoundation.framework
- CoreLocation.framework
- CoreTelephony.framework
- SafariServices.framework
- MobileCoreServices.framework
- WebKit.framework
- SystemConfiguration.framework
- AdSupport.framework
- ImageIO.framework
- AudioToolbox.framework
- libc++.tbd
- libz.tbd
- libbz2.tbd
- libsqlite3.tbd
- SpriteKit.framework
2.6. 模拟器支持说明(5.10.2 起)
⚠️ 破坏性变更:5.10.2 起 SDK 不再替接入方工程排除模拟器 arm64 架构。使用 Apple Silicon(M 系列芯片)Mac 的接入方请按本节自查,否则模拟器构建可能出现编译/链接失败。
2.6.1 变更说明
- 5.10.2 起 SDK 产物同时提供真机 arm64 与模拟器 arm64 + x86_64 切片,接入方可以在 Apple Silicon 上以原生 arm64 架构构建、运行模拟器。
- 5.10.1 及以前,SDK 会向宿主工程写入
EXCLUDED_ARCHS[sdk=iphonesimulator*] = arm64,把整个工程的模拟器架构强制为 x86_64,同时也顺带兼容了工程内其它没有 arm64 模拟器切片的第三方库、自建 prebuilt 静态库。5.10.2 移除了该设置,这部分兼容工作需由接入方自行处理。
2.6.2 影响范围
| 场景 | 是否受影响 |
|---|---|
| 真机构建、Archive、提审上架 | 不受影响 |
| Intel 芯片 Mac 上的模拟器 | 不受影响(Intel 机器模拟器只能是 x86_64) |
| Apple Silicon 上的模拟器 | 取决于工程内依赖是否提供 arm64 模拟器切片 |
2.6.3 典型报错与自查
Apple Silicon 上模拟器默认以 arm64 构建,如果工程内存在没有 arm64 模拟器切片的第三方库(或自建 prebuilt 静态库),会出现链接失败:
ld: building for 'iOS-simulator', but linking in object file (.../BaiduMobAdSDK.framework/BaiduMobAdSDK[arm64][2](BaiduMobAdSDK_vers.o)) built for 'iOS'
clang: error: linker command failed with exit code 1 (use -v to see invocation)自查依赖是否包含 arm64 模拟器切片:
// framework:输出包含 arm64 与 x86_64 即为包含模拟器切片
lipo -info Pods/BaiduMobAdSDK/BaiduMobAdSDK.framework/BaiduMobAdSDK
// xcframework:查看 Info.plist 的 AvailableLibraries,含 arm64 / simulator 的可用
cat Pods/WindSDK/SDK/WindSDK.xcframework/Info.plist2.6.4 解决方案
方案一:为工程设置 Excluded Architectures(推荐,改动最小)
Xcode → TARGETS → Build Settings → Architectures → Excluded Architectures,新增一项:key 选择 iOS Simulator,值填 arm64。
方案二:Podfile 中统一设置
post_install do |installer|
installer.aggregate_targets.each do |target|
target.user_project.native_targets.each do |native_target|
native_target.build_configurations.each do |config|
config.build_settings['EXCLUDED_ARCHS[sdk=iphonesimulator*]'] = 'arm64'
end
end
end
end注意:以上两种方式都会让模拟器构建退回 x86_64(依赖 Rosetta),编译与运行速度会有所下降,但兼容性最好。
2.6.5 渠道对模拟器的支持情况
(1)当前不提供模拟器切片的渠道(适配器仅提供真机 arm64 切片)
| 渠道 | Pod Code |
|---|---|
| 百度 | pod 'ToBid-iOS/BaiduAdapter' |
| 旺脉 | pod 'ToBid-iOS/WangMaiAdapter' |
| 泛为 | pod 'ToBid-iOS/PTGAdapter' |
| AppLovin | pod 'ToBid-iOS/AppLovinAdapter' |
| IronSource | pod 'ToBid-iOS/IronSourceAdapter' |
| Mintegral | pod 'ToBid-iOS/MintegralAdapter' |
| 趣盟 | pod 'ToBid-iOS/QuMengAdapter' |
| UnityAds | pod 'ToBid-iOS/UnityAdsAdapter' |
| Vungle | pod 'ToBid-iOS/VungleAdapter' |
上述渠道在模拟器上无法编译(真机构建、Archive 不受影响)。若需在模拟器上调试,可仅在模拟器构建中去掉对应 Adapter 依赖,或用不同的 Podfile 配置区分真机与模拟器。
(2)官方 Pod 自身会排除模拟器 arm64 的渠道
腾讯优量汇(GDTMobSDK)、京媒(JADYun)等渠道的官方 Pod 会向宿主工程写入同样的 EXCLUDED_ARCHS[sdk=iphonesimulator*] = arm64,接入后模拟器仍以 x86_64 构建。此情况编译不受影响,但也无法获得原生 arm64 模拟器的收益。
(3)其它注意事项
领摩(AdbidSDK)仅提供 arm64 模拟器切片,没有 x86_64 模拟器切片;使用 Intel 芯片 Mac,或按 2.6.4 排除了 arm64 的工程,构建模拟器时会失败。