Last Updated on : 2024-06-03 07:10:12download
This topic describes generic configurations to integrate a UI BizBundle of Cube App SDK with your iOS project. For more information, see tuya-bizbundle-ios-sdk-sample-objc on GitHub.
CocoaPods component | Description | Required |
---|---|---|
ThingSmartBizCore | The basic service library that is used to enable a BizBundle and customize certain features. | Yes |
ThingModuleServices | The protocol implemented by a BizBundle module. | Yes |
ThingSmartXXXBizBundle | A specific BizBundle component. | No |
ThingSmartBizCore
and ThingModuleServices
are the basic libraries to integrate BizBundles.
Enables a BizBundle and customizes certain features.
Theme colors and custom features
Implement the following code block to generate the file thing_custom_config.json
and put it in your project directory:
{
"config": {
"appId": 123,
"thingAppKey": "xxxxxxxxxxxx",
"appScheme": "ThingSmart",
"hotspotPrefixs": ["SmartLife"],
"needBle": true
},
"colors":{
"themeColor": "#FF5A28",
}
}
Parameters
Parameter | Description | Type | Yes | Default value |
---|---|---|---|---|
appId | The app ID. Log in to the Tuya Developer 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://platform.tuya.com/oem/app?id=888888 is 888888 . |
Number | Yes | None |
thingAppKey | The value of AppKey for the SDK that is created on the Tuya Developer Platform. | String | Yes | None |
appScheme | The value of Channel ID for the SDK that is created on the Tuya Developer 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 that 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 The instance that 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 The class that 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;
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 BizBundle, all BizBundles support internal navigation by means of push. Therefore, RootViewController
must be configured in your project.
Provides the protocol implemented by a BizBundle module.
Add the following code block to the Podfile
to add the basic library TuyaSmartBizCore
:
source 'https://github.com/tuya/tuya-private-specs.git'
source 'https://cdn.cocoapods.org/'
platform :ios, '11.0'
target 'your_target_name' do
# Adds the Tuya Cube App SDK.
pod "ThingSmartHomeKit"
# Adds the required BizBundles.
pod "ThingSmartXXXBizBundle"
end
In the root directory of your project, run pod update
to integrate a third-party library. For more information about CocoaPods, see CocoaPods Guides.
Customize the settings to initialize a BizBundle:
{
"config": {
"appId": 123,
"thingAppKey": "xxxxxxxxxxxx",
"appScheme": "ThingSmart"
},
"colors":{
"themeColor": "#FF5A28",
}
}
Generate the file thing_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.
The multilingual settings of UI BizBundles follow your project settings. If your project does not support multilingual settings, the target UI BizBundles uses English as the default language.
By calling the following APIs, you can switch to multiple languages:
/// Switch the app language, if the 'language' is passed as nil, then use the system language.
/// @param language Use the key in the returned information from the localizedLanguageNames method.
- (void)languageSwitchTo:(NSString *_Nullable)language;
/// Return supported languages.
/// @return
/// key: language IDs for all the localizations contained in the bundle, e.g. 'en'.
/// value: language name.
- (NSDictionary<NSString*, NSString*>* _Nonnull)supportedLanguages;
Example
// Check the supported languages
NSDictionary *dic = [[ThingSmartBizCore sharedInstance] supportedLanguages];
// Switch to the specified language
[[ThingSmartBizCore sharedInstance] languageSwitchTo:@"ja"];
When the language of the iOS app is switched, you need to call the [ThingSmartSDK sharedInstance].deviceToken = deviceToken;
method again. This will notify the cloud to switch languages, including the messages pushed by the cloud. Specifically, it is generally recommended to set this value in the system’s callback method application:didRegisterForRemoteNotificationsWithDeviceToken:
. The example is as follows:
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
[ThingSmartSDK sharedInstance].deviceToken = deviceToken;
}
This way, the backend will immediately receive updates whenever the language of the app changes. This step is important to make sure that your app can provide a stable, personalized experience to your global users.
Is this page helpful?
YesFeedbackIs this page helpful?
YesFeedback