1. 接入前准备
Before integration, make sure the following requirements are ready.
- iOS 工程可正常编译运行
- 已获取平台分配的
appKey - 已拿到 SDK 分发包:
hfsdk.xcframework - 使用真机联调与测试,当前分发包仅含
ios-arm64,不支持模拟器
面向第三方 iOS 宿主 App 的工程接入说明,覆盖 SDK 导入、初始化、结果回调、广告弹框接口、错误处理与上线前检查。
A third-party iOS host app integration guide covering SDK import, initialization, callbacks, ad overlay APIs, error handling and pre-launch checks.
当前分发包仅包含 ios-arm64,请使用真机完成联调与测试;模拟器环境不在本版本支持范围内。
The current distribution only includes ios-arm64. Please test on a real device; simulator builds are not supported in this package.
Before integration, make sure the following requirements are ready.
appKeyhfsdk.xcframeworkios-arm64,不支持模拟器Import the framework into your Xcode project and configure embedding.
hfsdk.xcframework 拖入 Xcode 工程。General -> Frameworks, Libraries, and Embedded Content 中添加 hfsdk.xcframework。Embed & Sign,也可按宿主工程策略调整。在 App 冷启动早期调用一次,通常放在 AppDelegate 中。
Call initialization once during early cold start, usually in AppDelegate.
#import <hfsdk/hfsdk.h>
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[HFSDKManager init:application appKey:@"<YOUR_APP_KEY>"];
return YES;
}
import hfsdk
func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
HFSDKManager.initialize(withApplication: application, appKey: "<YOUR_APP_KEY>")
return true
}
推荐使用初始化 completion 接口获取结果,回调会在主线程触发。
Use the completion API to receive initialization results. The callback is invoked on the main thread.
[HFSDKManager init:application
appKey:@"<YOUR_APP_KEY>"
completion:^(BOOL success, NSString * _Nullable reason) {
if (success) {
NSLog(@"[HFSDK] init success");
} else {
NSLog(@"[HFSDK] init failed, reason=%@", reason ?: @"unknown");
}
}];
HFSDKManager.initialize(with: application, appKey: "<YOUR_APP_KEY>") { success, reason in
if success {
print("[HFSDK] init success")
} else {
print("[HFSDK] init failed, reason=\(reason ?? "unknown")")
}
}
每次 initialize 调用最多回调一次。success == false 时,可通过 reason 获取失败或状态原因,例如 empty_app_key、stopped。
Each initialize call triggers at most one callback. When success == false, use reason to inspect the failure or status reason.
SDK 提供宿主可主动调用的全屏弹框接口,推荐使用成功/失败双回调。
The SDK provides a host-triggered full-screen overlay API. The success and error callbacks are recommended.
[HFSDKManager showAd:^(HFAdOverlayResult *result) {
NSLog(@"[HFSDK][showAd][dismiss] duration=%.0f clickStatus=%ld reason=%ld",
result.durationSec,
(long)result.clickStatus,
(long)result.closeReason);
} onError:^(NSError *error) {
NSLog(@"[HFSDK][showAd][error] domain=%@ code=%ld message=%@",
error.domain,
(long)error.code,
error.localizedDescription ?: @"unknown");
}];
onDismiss 仅在展示成功并关闭时回调onError 仅在展示失败时回调,不会展示 WebViewOpen with the system browser.
[HFSDKManager showAd:^(HFAdOverlayResult *result) {
NSLog(@"[HFSDK][showAd][browser] duration≈%.0f clickStatus=%ld",
result.durationSec,
(long)result.clickStatus);
} openInBrowser:YES onError:^(NSError *error) {
NSLog(@"[HFSDK][showAd][error] domain=%@ code=%ld message=%@",
error.domain,
(long)error.code,
error.localizedDescription ?: @"unknown");
}];
openInBrowser 说明
openInBrowser 默认 NO。传 YES 后 App 会跳到系统浏览器,SDK 无法观测浏览器内点击和后续跳转;成功路径仅在 App 确实进入后台并回到前台后回调。
openInBrowser defaults to NO. When set to YES, the app opens the system browser and the SDK cannot observe clicks or later navigation inside that browser.
Common error codes.
| 错误码 | 说明 |
|---|---|
HFAdErrorCodeNoURL | 当前无可用 URL |
HFAdErrorCodeNoScene | 未找到前台 Scene |
HFAdErrorCodeInvalidURL | URL 非法 |
HFAdErrorCodeNavigationFailed | 页面加载或导航失败 |
HFAdErrorCodeOpenInBrowserTimeout | 外部浏览器模式下,系统未在等待窗口内触发 App 进入后台,无法确认展示时长 |
onDismiss 回调字段onDismiss callback fields.
durationSec:展示时长,单位为秒clickStatus:点击状态,取值为 HFAdClickStatusYes、No、Unknown;外部浏览器模式为 UnknowncloseReason:关闭原因,取值为 userClose 或 interrupted当宿主需要主动停止时调用:
Call this method when the host app needs to stop the SDK manually.
[HFSDKManager stopSDK];
停止后若要重启,需再次调用初始化接口。
To restart after stopping, call the initialization API again.
Minimum checklist before launch.
showAd:onError:,可分别收到成功关闭与失败回调并记录结果。Security recommendations for host apps.
appKey 不要硬编码在可公开仓库。Recommended support information for integration partners.