General SDK

更新时间:
复制 MD 格式

The general SDK helps you initialize and configure all other SDKs for global settings, such as language and country.

Initialization

For more information about initializing the SDK, see SDK Initialization.

Country settings

  1. Display the country and region list page

    • Call the default page

      #import <IMSIotSmart/IMSIotSmart.h>
      // Use the country selection UI provided by the SDK.
        [[IMSIotSmart sharedInstance] showCountryListInNavigationController:self.navigationController callback:^(IMSIotCountry * _Nullable country) {
          // This is the callback for when a country is selected using the SDK's country selection UI.
          NSLog(@"selected country:%@",country);
        }];
    • Customizing the UI page

      #import <IMSIotSmart/IMSIotSmart.h>
      [[IMSIotSmart sharedInstance] getCountryList:^(NSError * _Nullable error, NSArray<IMSIotCountry *> * _Nullable countryList) {
          // The returned countryList is raw data.
         // Use this raw data to design a UI that renders the country list.
        }];
  2. Set the country

    #import <IMSIotSmart/IMSIotSmart.h> 
    // For apps developed with SDKs for API Level 9 or later, the app does not need to restart when you switch countries. The restart logic is not required within IMSIotSmart.
    // If no other services depend on this logic, you can ignore the needRestartApp parameter.
    [[IMSIotSmart sharedInstance] setCountry:_selectCountry callback:^(BOOL needRestartApp) {
        
     }];

Language settings

IoT Platform currently supports 24 languages, including Chinese (zh-CN), English (en-US), French (fr-FR), German (de-DE), Japanese (ja-JP), Korean (ko-KR), Spanish (es-ES), Russian (ru-RU), Italian (it-IT), Hindi (hi-IN), Portuguese (pt-PT), Polish (pl-PL), Dutch (nl-NL), Danish (da-dk), Czech (cs-CZ), Slovak (sk-SK), Swedish (sv-SE), Traditional Chinese (zh-Hant), Turkish (tr-TR), Hungarian (hu-HU), Vietnamese (vi-VN), Indonesian (in-ID), Arabic (ar-SA), and Thai (th-TH).

  • Set the language

    You can set the language for SDKs such as API Gateway, User Account, Push, and Plug-in.

    #import <IMSIotSmart/IMSIotSmart.h>
    NSString *language = @"zh-CN";
    [[IMSIotSmart sharedInstance] setLanguage:language];
  • Retrieve the current language

    You can retrieve the language setting for SDKs such as API Gateway, User Account, Push, and Plug-in.

    #import <IMSIotSmart/IMSIotSmart.h>
    // Get the current language of the SDK. If a language has not been set, this method returns the current system language.
    NSString *language = [[IMSIotSmart sharedInstance] getLanguage];

Debug unpublished products

You can set the product scope for the app's device provisioning list. The possible values are as follows.

  • PRODUCT_SCOPE_ALL: Includes all published and unpublished products in the current project.

  • PRODUCT_SCOPE_PUBLISHED: Includes only published products. For production apps, select PRODUCT_SCOPE_PUBLISHED.

#import <IMSIotSmart/IMSIotSmart+scope.h>
[[IMSIotSmart sharedInstance] configProductScope:PRODUCT_SCOPE_ALL];

Set the log switch

For more information about setting the log switch, see Log SDK.

Get the server ID for the app's current connection

If your app can connect to multiple business servers, you can optimize the user experience by selecting a server based on the current logon server. Call the following API to retrieve the server ID of the current connection. This ID helps you select a region that provides the fastest connection for other business servers.

[[IMSIotSmart sharedInstance]  shortRegionId];
Note
  • This API operation is available only in version 1.2.2 and later. The following code shows an example of how to upgrade.

    pod 'IMSIotSmart', '1.2.2'
  • Call this API operation only after the app has logged on. Otherwise, you cannot retrieve an accurate server ID.

The platform returns the following server ID values.

  • 0: China (Shanghai)

  • 1: Singapore

  • 3: US (Virginia)

  • 4: Germany (Frankfurt)

SDK API Reference

For more information about the API comments for the IoT Platform SDKs, see the SDK API Reference.