API通道SDK,提供IoT业务协议封装的HTTPS请求能力,并通过整合安全组件来提升通道的安全性。

依赖 SDK 概述
日志 基础依赖SDK,提供客户端统一日志打印,日志等级控制,分模块日志隔离等能力

初始化

初始化前需确保已集成安全图片,初始化的操作请参见SDK初始化

使用说明

API 调用示例如下。

#import <IMSApiClient/IMSApiClient.h>

// 构建请求
NSDictionary *params = @{@"input":@"测试"};
IMSIoTRequestBuilder *builder = [[IMSIoTRequestBuilder alloc] initWithPath:@"/kit/debug/ping"
                                                                apiVersion:@"1.0.0"
                                                                    params:params];
// 可选参数
// [builder setHost:@"xxx"];//指定API host
// [builder setScheme:@"https"];

//通过 IMSRequestClient 发送请求
[IMSRequestClient asyncSendRequest:builder.build responseHandler:^(NSError * _Nullable error, IMSResponse * _Nullable response) {
    if (error) {
        //处理Error,非服务端返回的错误都通过该Error回调
    }
    else {
        if (response.code == 200) {
            //成功,处理response.data
        }
        else {
            //处理服务端错误,可通过response.localizedMsg展示错误Toast
        }
    }
}];     

超时时长设置

指定API请求的超时时长。

// 设置全局超时时长,对所有API请求都生效,不设置默认10s
[IMSConfiguration sharedInstance].timeoutInterval = 10;

// 针对局部请求超时时长设置
NSDictionary *params = @{@"input":@"测试"};
IMSIoTRequestBuilder *builder = [[IMSIoTRequestBuilder alloc] initWithPath:@"/kit/debug/ping"
                                                                apiVersion:@"1.0.0"
                                                                    params:params];
// 可选参数,不设置默认使用全局配置超时时长
builder.timeoutInterval = 10;

//通过 IMSRequestClient 发送请求
[IMSRequestClient asyncSendRequest:builder.build responseHandler:^(NSError * _Nullable error, IMSResponse * _Nullable response) {
    if (error) {
        //处理Error,非服务端返回的错误都通过该Error回调
    }
    else {
        if (response.code == 200) {
            //成功,处理response.data
        }
        else {
            //处理服务端错误,可通过response.localizedMsg展示错误Toast
        }
    }
}];