框架接入

更新时间:2024-03-18 08:12:14下载pdf

业务包组件

Cocoapods 组件 说明 是否必选
ThingSmartBizCore 业务基础处理库,用于启动业务包以及自定义一些功能 必选
ThingModuleServices 业务包模块实现的协议 必选
ThingCommercialLightingXXXBizBundle 各种业务包实现组件 可选

ThingSmartBizCoreThingModuleServices 是使用业务包必须要依赖的基础库。

核心库(ThingSmartBizCore)

提供启动业务包以及自定义配置功能。

主题色及自定义配置功能

该部分的配置,需要客户按照如下方式生成一份名为 thing_custom_config.json 的文件放入工程目录下:

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

参数介绍

参数 说明 类型 必选 默认值
appId 应用 ID,在涂鸦 IoT 开发平台进入您的应用/SDK 管理页面。应用页面 URL 中的 ID 参数即为 appId,例如链接为 https://iot.tuya.com/oem/app?id=888888,则 appId888888 Number
thingAppKey 涂鸦 IoT 开发平台 中对应 SDK 中的 AppKey String
appScheme 涂鸦 IoT 开发平台 中对应 SDK 中的 渠道标识符 String
hotspotPrefixs 配网设备热点前缀 Array [“SmartLife”]
needBle 是否需要支持蓝牙设备配网 Boolean true
themeColor UI 主题色设置 String #FF5A28

接口介绍

业务包基础库,提供业务包调用的入口方法,同时也提供了您需要实现协议服务的注册方法。具体提供的方法如下:

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

/**
 * Register an instance for service that cannot 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 conforms to the service protocol, strong reference
 *                  unregister if nil
 */
- (void)registerService:(Protocol *)service withInstance:(id)instance;

/**
 * Register a class for service that cannot 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 conforms to the service protocol, [cls new] to get instance
 *                  unregister if nil
 */
- (void)registerService:(Protocol *)service withClass:(Class)cls;

/**
 * Register route handler for the route that cannot 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 the route can be handled, otherwise return false
 */
- (void)registerRouteWithHandler:(BOOL(^)(NSString *url, NSDictionary *raw))handler;

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

账号登录成功后,务必调用 - (void)updateConfig 接口更新必要的缓存数据,否则部分业务包将无法正常使用。

除设备控制 UI 业务包外,其余业务包均通过 push 方式进行内部跳转。因此,确保您的工程已设置了 RootViewController

服务协议(ThingModuleServices)

提供各个业务包实现的服务协议。

集成业务包

使用 CocoaPods 集成

Podfile 文件中添加以下内容完成业务包核心库添加:

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

target 'your_target_name' do
    # 添加商用照明 App SDK
    pod "ThingCommercialLightingKit"
    # 若需要相关业务包功能,添加相关业务库
    pod "ThingCommercialLightingXXXBizBundle"
end

然后在项目根目录下执行 pod update 命令,集成第三方库。有关 CocoaPods 的使用,参考 CocoaPods Guide

自定义配置项

填写业务包初始化需要的配置。

{
    "config": {
        "appId": 123,
        "thingAppKey": "xxxxxxxxxxxx",
        "appScheme": "thingSmart"
    },
    "colors":{
        "themeColor": "#FF5A28",
    }
}

生成名为 thing_custom_config.json 的 json 文件,放到工程根目录下。

商用照明业务包准备工作已经完成,可以开始业务包的使用。具体业务包的集成使用,参考对应的业务包文档。

多语言

带 UI 业务包的多语言将会根据您的工程所支持的多语言,来显示相对应的语言。如果您的工程不做多语言配置,则业务包 UI 以英文为默认语言显示。