Last Updated on : 2024-10-28 08:33:20download
This topic describes generic configurations to integrate a UI BizBundle of Smart Life 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-pod-specs.git'
source 'https://cdn.cocoapods.org/'
platform :ios, '11.0'
target 'your_target_name' do
# Adds the Tuya Smart Life 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 and replace language translations.
/// 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 'supportedLanguages' method.
- (void)languageSwitchTo:(ThingSmartBizLanguageKey _Nullable)language;
/**
Returns a dictionary of supported languages with complete translations.
This method provides a list of languages that have full translation support. Each entry in the dictionary maps a language code to its corresponding language name.
@return A dictionary where keys are language codes (e.g., "en", "fr") and values are the full names of the languages.
key:language IDs for all the localizations contained in the bundle. e.g. 'en'
value:language name
*/
- (NSDictionary<ThingSmartBizLanguageKey, NSString *> *_Nonnull)recommendedLanguages;
/**
Returns the current language key being used by the application.
This method provides the language key that represents the current language setting of the application.
It reflects the language that the app is currently using for its interface and content. This can be
useful for determining the current localization and for displaying language-specific content.
@return The 'ThingSmartBizLanguageKey' indicates the current language setting of the app.
*/
- (ThingSmartBizLanguageKey)currentLanguageKey;
/**
Sets a language interceptor to customize language string replacements.
This method allows you to set a language interceptor that conforms to the 'ThingSmartBizLanguageInterceptorProtocol'.
The interceptor is used to handle custom language string replacements within the application.
@param interceptor An object conforming to 'ThingSmartBizLanguageInterceptorProtocol' to handle language string replacements.
@throws NSException Throws a ThingSmartBizCoreExceptionName if the interceptor is nil or if the [ThingLanguageLoader sharedInstance].delegate is already set.
*/
- (void)setLanuageInterceptor:(id<ThingSmartBizLanguageInterceptorProtocol>)interceptor;
Example
// Check the supported languages
NSDictionary *dic = [[ThingSmartBizCore sharedInstance] recommendedLanguages];
// Switch to the specified language
[[ThingSmartBizCore sharedInstance] languageSwitchTo:ThingSmartBizLanguageKeyJapanese];
// Get current language
ThingSmartBizLanguageKey lang = [[ThingSmartBizCore sharedInstance] currentLanguageKey]
// Replace language translation
[[ThingSmartBizCore sharedInstance] setLanuageInterceptor: xxxx];
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