AISDK iOS API文档

AISDK iOS API文档

1 初始化启动接口

接口描述:

启动 SDK

接口定义:

@objc(startSdkWithAppId:onSuccess:onFailure:)
public static func startSdk(
        appId: String,
        onSuccess: AISDKSuccessBlock? = nil,
        onFailure: AISDKFailureBlock? = nil
    )

接口说明:

参数 参数说明
appId 应用标识 APPID
onSuccess 初始化成功回调
onFailure 初始化失败回调

接口示例:

ObjC调用方式:

  /*
            onFailure中的错误码说明:
            -30001:网络错误
            */

[AISDK startSdkWithAppId:AISDKDemoAppId onSuccess:^(id  _Nullable res) {
    self.sdkInitialized = YES;
    self.statusLabel.text = @"状态:初始化成功";
    NSLog(@"[AISDKDemo] startSdk success");
} onFailure:^(NSError * _Nonnull error) {
    self.sdkInitialized = NO;
    self.statusLabel.text = [NSString stringWithFormat:@"状态:初始化失败 (%@)", @(error.code)];
    NSLog(@"[AISDKDemo] startSdk failure code:%@ msg:%@", @(error.code), error.localizedDescription);
}];

Swift调用方式:

AISDK.startSdk(appId: DemoConfig.appId, onSuccess: { [weak self] _ in
    self?.sdkReady = true
    self?.statusLabel.text = "SDK 初始化成功"
}, onFailure: { [weak self] error in
        guard let self else { return }
    self.sdkReady = false
    self.statusLabel.text = "SDK 初始化失败:\(error.code) \(error.localizedDescription)"
})

2 请求智能体

接口描述:

获取智能体 url,展示智能体webview。需要先初始化完成后,才能调用请求智能体API。

接口定义:

  @objc(loadAgentWithAgentId:show:presentingViewController:onSuccess:onFailure:)
    public static func loadAgent(
        agentId: String,
        show rawShowValue: NSNumber?,
        presentingViewController: UIViewController? = nil,
        onSuccess: AISDKLoadAgentSuccessBlock? = nil,
        onFailure: AISDKFailureBlock? = nil
    )

接口说明:

参数 参数说明
agentId 智能体ID
show 是否展示网页webview
onSuccess 加载智能体成功回调
onFailure 加载智能体失败回调

接口示例:

ObjC调用方式:

    /*
     onFailure中的错误码说明:
     -30001:网络错误

     -40001:频率超限,1s1次
     -40002:重复请求
     -40003:未注册成功
     -40004:agentid 不合法
     -40005:show参数不合法
     -40100: webview展示失败
     */

 [AISDK loadAgentWithAgentId:AISDKDemoAgentId
                            show:@YES
      presentingViewController:self
                       onSuccess:^(NSString * _Nonnull url) {
        NSLog(@"[AISDKDemo] load agent success:%@ ",url);
    } onFailure:^(NSError * _Nonnull error) {
        NSLog(@"[AISDKDemo] load agent failed:%@ %@ ",@(error.code),error.localizedDescription);
    }];

Swift调用方式:

   AISDK.loadAgent(
            agentId: DemoConfig.agentId,
            show: true,
            presentingViewController: self,
            onSuccess: { [weak self] _ in
                self?.statusLabel.text = "Agent 加载成功"
            },
            onFailure: { [weak self] error in
                self?.statusLabel.text = "Agent 加载失败:\(error.code) \(error.localizedDescription)"
            }
        )

文档中心搜索

技术
咨询

微信扫一扫

随时联系技术支持

在线
咨询