API channel SDK

更新时间:
复制 MD 格式

The API channel SDK sends HTTPS requests by encapsulating them in the IoT protocol. It also integrates security components to enhance channel security.

Dependent SDK

Overview

Log

A basic dependent SDK for unified client-side log printing, log level control, and log fencing by module.

Initialization

To initialize the SDK, see SDK Initialization.

Usage

The following code shows an example of an API call.

#import <IMSApiClient/IMSApiClient.h>

// Build the request
NSDictionary *params = @{@"input":@"test"};
IMSIoTRequestBuilder *builder = [[IMSIoTRequestBuilder alloc] initWithPath:@"/kit/debug/ping"
                                                                apiVersion:@"1.0.0"
                                                                    params:params];
// Optional parameters
// [builder setHost:@"xxx"];// Specify the API host
// [builder setScheme:@"https"];

// Send the request using IMSRequestClient
[IMSRequestClient asyncSendRequest:builder.build responseHandler:^(NSError * _Nullable error, IMSResponse * _Nullable response) {
    if (error) {
        // Handle the error. Errors not returned by the server-side are returned through this error callback.
    }
    else {
        if (response.code == 200) {
            // Success. Process response.data.
        }
        else {
            // Handle server-side errors. Display an error toast using response.localizedMsg.
        }
    }
}];     

Timeout settings

You can specify the timeout period for API requests.

// Set the global timeout period. This applies to all API requests. The default is 10 s.
[IMSConfiguration sharedInstance].timeoutInterval = 10;

// Set the timeout period for a specific request
NSDictionary *params = @{@"input":@"test"};
IMSIoTRequestBuilder *builder = [[IMSIoTRequestBuilder alloc] initWithPath:@"/kit/debug/ping"
                                                                apiVersion:@"1.0.0"
                                                                    params:params];
// Optional parameter. If not set, the global timeout period is used.
builder.timeoutInterval = 10;

// Send the request using IMSRequestClient
[IMSRequestClient asyncSendRequest:builder.build responseHandler:^(NSError * _Nullable error, IMSResponse * _Nullable response) {
    if (error) {
        // Handle the error. Errors not returned by the server-side are returned through this error callback.
    }
    else {
        if (response.code == 200) {
            // Success. Process response.data.
        }
        else {
            // Handle server-side errors. Display an error toast using response.localizedMsg.
        }
    }
}];