CloudX iOS SDK
需要 iOS 14.0+ 和 Xcode 12.0+。安装
CocoaPods
Podfile
复制
platform :ios, '14.0'
target 'YourApp' do
use_frameworks!
# 核心 SDK
pod 'CloudXCore'
# 适配器(根据需要添加)
pod 'CloudXMetaAdapter' # Meta Audience Network
pod 'CloudXVungleAdapter' # Vungle (Liftoff)
# CloudX Renderer(用于测试广告)
pod 'CloudXRenderer'
end
复制
pod install --repo-update
CloudXRenderer 处理支持 MRAID 3.0 和 VAST 4.0 的广告素材渲染。目前仅用于渲染测试广告。
初始化
复制
#import <CloudXCore/CloudXCore.h>
[[CloudXCore shared] initializeSDKWithAppKey:@"your-app-key-here"
testMode:NO
completion:^(BOOL success, CLXError * _Nullable error) {
if (success) {
NSLog(@"CloudX SDK 初始化成功");
} else {
NSLog(@"CloudX SDK 初始化失败: %@", error.localizedDescription);
}
}];
广告集成
横幅广告
复制
@interface YourViewController () <CLXBannerDelegate>
@property (nonatomic, strong) CLXBannerAdView *bannerAd;
@end
@implementation YourViewController
- (void)createBannerAd {
self.bannerAd = [[CloudXCore shared] createBannerWithPlacement:@"your-banner-placement"
viewController:self
delegate:self
tmax:nil];
if (self.bannerAd) {
self.bannerAd.translatesAutoresizingMaskIntoConstraints = NO;
[self.view addSubview:self.bannerAd];
[NSLayoutConstraint activateConstraints:@[
[self.bannerAd.bottomAnchor constraintEqualToAnchor:self.view.safeAreaLayoutGuide.bottomAnchor],
[self.bannerAd.centerXAnchor constraintEqualToAnchor:self.view.centerXAnchor],
[self.bannerAd.widthAnchor constraintEqualToConstant:320],
[self.bannerAd.heightAnchor constraintEqualToConstant:50]
]];
[self.bannerAd load];
}
}
#pragma mark - CLXBannerDelegate
- (void)didLoadAd:(CLXAd *)ad {
NSLog(@"横幅广告加载成功");
}
- (void)didFailToLoadAdWithError:(CLXError *)error {
NSLog(@"横幅广告加载失败: %@", error.localizedDescription);
}
- (void)didDisplayAd:(CLXAd *)ad {
NSLog(@"横幅广告已展示");
}
- (void)didClickAd:(CLXAd *)ad {
NSLog(@"横幅广告被点击");
}
- (void)didHideWithAd:(CLXAd *)ad {
NSLog(@"横幅广告已隐藏");
}
@end
MREC 广告
复制
@interface YourViewController () <CLXBannerDelegate>
@property (nonatomic, strong) CLXBannerAdView *mrecAd;
@end
@implementation YourViewController
- (void)createMRECAd {
self.mrecAd = [[CloudXCore shared] createMRECWithPlacement:@"your-mrec-placement"
viewController:self
delegate:self];
if (self.mrecAd) {
self.mrecAd.translatesAutoresizingMaskIntoConstraints = NO;
[self.view addSubview:self.mrecAd];
[NSLayoutConstraint activateConstraints:@[
[self.mrecAd.centerXAnchor constraintEqualToAnchor:self.view.centerXAnchor],
[self.mrecAd.bottomAnchor constraintEqualToAnchor:self.view.safeAreaLayoutGuide.bottomAnchor constant:-20],
[self.mrecAd.widthAnchor constraintEqualToConstant:300],
[self.mrecAd.heightAnchor constraintEqualToConstant:250]
]];
[self.mrecAd load];
}
}
#pragma mark - CLXBannerDelegate
- (void)didLoadAd:(CLXAd *)ad {
NSLog(@"MREC 广告加载成功");
}
- (void)didFailToLoadAdWithError:(CLXError *)error {
NSLog(@"MREC 广告加载失败: %@", error.localizedDescription);
}
- (void)didDisplayAd:(CLXAd *)ad {
NSLog(@"MREC 广告已展示");
}
- (void)didClickAd:(CLXAd *)ad {
NSLog(@"MREC 广告被点击");
}
- (void)didHideWithAd:(CLXAd *)ad {
NSLog(@"MREC 广告已隐藏");
}
@end
插屏广告
复制
@interface YourViewController () <CLXInterstitialDelegate>
@property (nonatomic, strong) CLXInterstitial *interstitialAd;
@end
@implementation YourViewController
- (void)createInterstitialAd {
self.interstitialAd = [[CloudXCore shared] createInterstitialWithPlacement:@"your-interstitial-placement"];
self.interstitialAd.delegate = self;
if (self.interstitialAd) {
[self.interstitialAd load];
}
}
- (void)showInterstitialAd {
if (self.interstitialAd.isReady) {
[self.interstitialAd showFromViewController:self];
} else {
NSLog(@"插屏广告尚未准备好");
}
}
#pragma mark - CLXInterstitialDelegate
- (void)didLoadAd:(CLXAd *)ad {
NSLog(@"插屏广告加载成功");
}
- (void)didFailToLoadAdWithError:(CLXError *)error {
NSLog(@"插屏广告加载失败: %@", error.localizedDescription);
}
- (void)didDisplayAd:(CLXAd *)ad {
NSLog(@"插屏广告已展示");
}
- (void)failToShowWithAd:(CLXAd *)ad error:(CLXError *)error {
NSLog(@"插屏广告展示失败: %@", error.localizedDescription);
}
- (void)didHideWithAd:(CLXAd *)ad {
NSLog(@"插屏广告已隐藏");
[self createInterstitialAd]; // 为下次使用重新加载
}
- (void)didClickWithAd:(CLXAd *)ad {
NSLog(@"插屏广告被点击");
}
@end
高级功能
调试日志
复制
// 在 SDK 初始化前启用详细日志
[CloudXCore setLoggingEnabled:YES];
测试模式
在初始化时传入testMode: true 以在开发期间启用测试广告:
复制
[[CloudXCore shared] initializeSDKWithAppKey:@"your-app-key" testMode:YES completion:^(BOOL success, CLXError *error) {
// 测试广告已启用
}];
隐私合规
CloudX SDK 通过从NSUserDefaults 读取标准 IAB 隐私字符串来支持 GDPR 和 CCPA 隐私合规。这些值通常由您的同意管理平台(CMP)自动设置。
支持的隐私密钥
| 密钥 | 描述 |
|---|---|
IABTCF_TCString | GDPR TC 字符串 |
IABTCF_gdprApplies | GDPR 是否适用(1 = 是,0 = 否) |
IABUSPrivacy_String | CCPA 隐私字符串 |
IABGPP_HDR_GppString | 全球隐私平台字符串 |
IABGPP_GppSID | GPP 部分 ID |
用户定向
复制
// 设置哈希用户 ID
[[CloudXCore shared] setHashedUserID:@"hashed-user-id"];
// 用户级定向(受隐私法规清除)
[[CloudXCore shared] setUserKeyValue:@"age" value:@"25"];
// 应用级定向(不受隐私法规影响)
[[CloudXCore shared] setAppKeyValue:@"app_version" value:@"1.2.0"];
// 清除所有键值对
[[CloudXCore shared] clearAllKeyValues];