English
English
简体中文
Contact Us
Register
Log In
layoutIndex

Integrate with Framework

Last Updated on : 2022-03-03 06:51:45download

BizBundle components

CocoaPods component Description Required
TuyaSmartBizCore The basic service library that is used to enable a BizBundle and customize certain features. Required
TYModuleServices The protocol implemented by a BizBundle module. Required
TuyaSmartXXXBizBundle A specific BizBundle component. No

TuyaSmartBizCore and TYModuleServices are the basic libraries to integrate with BizBundles.

TuyaSmartBizCore

Enables a BizBundle and customizes certain features.

Theme colors and custom features

Implement the following code block to generate the file ty_custom_config.json and put it in your project directory:

{
    "config": {
        "appId": 123,
        "tyAppKey": "xxxxxxxxxxxx",
        "appScheme": "tuyaSmart",
        "hotspotPrefixs": ["SmartLife"],
        "needBle": true
    },
   "colors":{
        "themeColor": "#FF5A28",
    }
}

Parameters

Parameter Description Type Required Default value
appId The app ID. Log in to the Tuya IoT Development Platform and go to the details page of your app or SDK. In the URL of this page, the ID parameter indicates the value of appId. For example, the value of appId specified by https://iot.tuya.com/oem/app?id=888888 is 888888. Number Yes None
tyAppKey The value of AppKey for the SDK that is created on the Tuya IoT Development Platform. String Yes None
appScheme The value of Channel ID for the SDK that is created on the Tuya IoT Development Platform. String Yes None
hotspotPrefixs The prefix of a device hotspot for pairing. Array No [“SmartLife”]
needBle Specifies whether Bluetooth devices can be paired. Boolean No true
themeColor The settings of UI theme colors. String No #FF5A28

API description

The basic library of BizBundles provides the methods to access BizBundles and the methods to register the required protocol services. Example:

/**
 * Get the instance which implement the special service protocol
 * eg:
 *  id<TYMallProtocol> impl = [[TuyaSmartBizCore sharedInstance] serviceOfProtocol:@protocol(TYMallProtocol)];
 *  [impl xxx]; // your staff...
 *
 * @param serviceProtocol service protocol
 * @return instance
 */
- (id)serviceOfProtocol:(Protocol *)service;

/**
 * Register an instance for service which can not be served by BizBundle itself
 * Each service can only register one instance or class at a time, whichever is the last
 *
 * @param service   service protocol
 * @param instance  instance which conform to the service protocol, strong reference
 *                  unregister if nil
 */
- (void)registerService:(Protocol *)service withInstance:(id)instance;

/**
 * Register a class for service which can not be served by BizBundle itself
 * Each service can only register one instance or class at a time, whichever is the last
 *
 *
 * @param service   service protocol
 * @param cls       class which conform to the service protocol, [cls new] to get instance
 *                  unregister if nil
 */
- (void)registerService:(Protocol *)service withClass:(Class)cls;

/**
 * Register route handler for route which can not be handled by BizBundle itself
 * @param handler   block to handle route
 *                  @param url  the route url
 *                  @param raw  the route raw data
 *                  @return true if route can be handled, otherwise return false
 */
- (void)registerRouteWithHandler:(BOOL(^)(NSString *url, NSDictionary *raw))handler;

/**
* Update config of biz resource
*
*/
- (void)updateConfig;

After login to the app, the API method - (void)updateConfig must be called to update cache data. Otherwise, certain BizBundles cannot be used as expected.

Except for the Device Control UI BizBundle, all BizBundles support internal navigation by means of push. Therefore, RootViewController must be configured in your project.

TYModuleServices

Provides the protocol implemented by a BizBundle module.

Integrate with BizBundles

Use CocoaPods for fast integration

Add the following code block to the Podfile to add the basic library TuyaSmartBizCore:

source "https://github.com/TuyaInc/TuyaPublicSpecs.git"
source 'https://cdn.cocoapods.org/'

target 'your_target_name' do
    # Adds the Tuya Smart Residence App SDK.
    pod "TuyaSmartResidenceKit"
    # Adds the required BizBundles.
    pod "TuyaSmartXXXBizBundle"
end

In the root directory of your project, run pod update to integrate with a third-party library. For more information about CocoaPods, see CocoaPods Guides.

Customize settings

Customize the settings to initialize a BizBundle:

{
    "config": {
        "appId": 123,
        "tyAppKey": "xxxxxxxxxxxx",
        "appScheme": "tuyaSmart"
    },
    "colors":{
        "themeColor": "#FF5A28",
    }
}

Generate the file ty_custom_config.json and put it in the root directory of your project.

Now, you can get started with your development based on the required BizBundles. For more information about the integration with a specific BizBundle, see its documentation.

Configure multilingual options

The multilingual settings of UI BizBundles follow your project settings. If your project does not support multilingual settings, the target UI BizBundles use English as the default language.