Last Updated on : 2022-06-23 09:17:05download
Device Control UI BizBundle for iOS is the core container of the panels for Powered by Tuya
(PBT) devices. Based on Tuya Smart Life App SDK for iOS, the BizBundle encapsulates the APIs to load and control panels and accelerates application development. The following features are supported:
Add the components of the Device Control UI BizBundle to the Podfile
and run the command pod update
.
source "https://github.com/tuya/TuyaPublicSpecs.git"
source 'https://cdn.cocoapods.org/'
target 'your_target_name' do
# TuyaSmart SDK
pod "TuyaSmartHomeKit"
# Adds the UI BizBundle.
pod 'TuyaSmartPanelBizBundle'
# Depends on the robot vacuum plug-ins to integrate with their features if needed.
# pod 'TuyaRNApi/Sweeper'
end
The UI BizBundle includes the open source React Native framework (v0.59.10).
If your iOS project does not integrate with React Native, follow the procedure in this topic to integrate with the UI BizBundle.
If your iOS project has integrated with React Native, perform the following steps to check whether the UI BizBundle can be integrated:
If both methods failed, the UI BizBundle cannot be integrated.
The BizBundle encapsulates a series of React Native API methods for panels. This requires specific declarations of privacy and permissions from Apple.
If a device panel supports album features such as the cloud album, add the following permission declaration to info.plist
of your project:
NSPhotoLibraryAddUsageDescription
If a device panel supports camera features such as the cloud album, add the following permission declaration to info.plist
of your project:
NSCameraUsageDescription
If a device panel supports location features, add the following permission declaration to info.plist
of your project:
NSLocationWhenInUseUsageDescription
If a device panel supports microphone features such as the music light panel, add the following permission declaration to info.plist
of your project:
NSMicrophoneUsageDescription
If a device panel supports Bluetooth features, add the following permission declaration to info.plist
of your project:
NSBluetoothAlwaysUsageDescription
NSBluetoothPeripheralUsageDescription
The UI BizBundle relies on the implementation of the protocol TYPanelProtocol
to provide services. You can view the TYPanelProtocol.h
file in the TYModuleServices
component.
@protocol TYPanelProtocol <NSObject>
NS_ASSUME_NONNULL_BEGIN
// Clears cached data of the panel.
- (void)cleanPanelCache;
/**
* Returns the device panel controller.
*
* @param deviceModel The device model.
* @param initialProps The custom initialization parameter to be set in `initialProps` of the RN application with the key 'extraInfo'.
* @param contextProps The context of the custom panel to be set in `Panel Context` with the key 'extraInfo'.
* @param completionHandler The callback of the view controller.
*/
- (void)getPanelViewControllerWithDeviceModel:(TuyaSmartDeviceModel *)deviceModel
initialProps:(nullable NSDictionary *)initialProps
contextProps:(nullable NSDictionary *)contextProps
completionHandler:(void (^ _Nullable)(__kindof UIViewController * _Nullable panelViewController, NSError * _Nullable error))completionHandler;
/**
* Returns the group panel controller.
*
* @param groupModel The group model.
* @param initialProps The custom initialization parameter to be set in `initialProps` of the RN application with the key 'extraInfo'.
* @param contextProps The context of the custom panel to be set in `Panel Context` with the key 'extraInfo'.
* @param completionHandler The callback of the view controller.
*/
- (void)getPanelViewControllerWithGroupModel:(TuyaSmartGroupModel *)groupModel
initialProps:(nullable NSDictionary *)initialProps
contextProps:(nullable NSDictionary *)contextProps
completionHandler:(void (^ _Nullable)(__kindof UIViewController * _Nullable panelViewController, NSError * _Nullable error))completionHandler;
// The RN version number.
- (NSString *_Nonnull)rnVersionForApp;
NS_ASSUME_NONNULL_END
@end
The UI BizBundle is used to load device panels and provide varied features depending on different devices. To ensure the normal use of these features, the UI BizBundle depends on the following protocols: TYSmartHomeDataProtocol
, TYDeviceDetailProtocol
, TYSettingsProtocol
, TYOTAGeneralProtocol
, TYGroupHandleProtocol
, TYRNCameraProtocol
, and TYCameraProtocol
.
Provides current home information required by the BizBundle. This protocol must be implemented.
/**
Returns the current home. If the current user does not have a home, `nil` is returned.
@return TuyaSmartHome
*/
- (TuyaSmartHome *)getCurrentHome;
Implements the activity of tapping and navigation in the top-right corner of the device panel.
/**
Tap the button in the top-right corner of the device panel to navigate to the device details page.
@param device The device.
@param group The group if any. It is optional.
*/
- (void)gotoDeviceDetailDetailViewControllerWithDevice:(TuyaSmartDeviceModel *)device group:(TuyaSmartGroupModel *)group;
Provides the optional switch to enable a certain sound effect on the app when device control DPs are sent. The following API method is implemented to return whether the sound effect is enabled:
/**
* Indicates whether the sound effect is enabled.
*/
- (BOOL)soundEnabled;
Enters the device panel and checks for device firmware updates. The following API method is implemented to check for device firmware updates:
/**
Checks for device firmware updates, and if any, shows the update prompt.
@param deviceModel The device that checks for firmware updates.
@param isManual Specifies whether to enable manual checking of firmware updates.
@param theme The theme color.
YES: Manually check for updates. A loading dialog box appears during the check. If a new update is found (check for updates, forced updates, and update notifications), OTA VC is displayed.
NO: Automatically check for updates. A loading dialog box does not appear during the check. When forced updates and update notifications are enabled, the firmware update prompt appears. Click OK to show OTA VC.
*/
- (void)checkFirmwareUpgrade:(TuyaSmartDeviceModel *)deviceModel isManual:(BOOL)isManual theme:(TYOTAControllerTheme)theme;
Implements the activity of navigation to a mesh group page on the panel for a Bluetooth mesh device. The following API method is implemented:
/**
Navigates to a local mesh group.
@available 1.0.0
@param params
@param success
@param failure
*/
- (void)impl_jumpToMeshLocalGroup:(NSDictionary*)params success:(RCTResponseSenderBlock)success failure:(RCTResponseErrorBlock)failure ;
Navigates to and loads the RN panel for an IP camera (IPC). If the BizBundle TuyaSmartCameraRNPanelBizBundle
is integrated, this protocol is not required.
/**
Returns the IPC RN panel.
@param devId The device ID of the IPC.
*/
- (UIViewController *)cameraRNPanelViewControllerWithDeviceId:(NSString *)devId;
Navigates to and loads the native panel of an IPC. If the BizBundle TuyaSmartCameraPanelBizBundle
is integrated, this protocol is not required.
/**
Returns the IPC native panel.
@param devId The device ID of the IPC.
@param uiName The UI name of the IPC. The value varies depending on different panel versions.
*/
- (UIViewController *)viewControllerWithDeviceId:(NSString *)devId uiName:(NSString *)uiName;
getCurrentHome
method provided by the protocol TYSmartHomeDataProtocol
must be implemented first.Objective-C
#import <TuyaSmartBizCore/TuyaSmartBizCore.h>
#import <TYModuleServices/TYSmartHomeDataProtocol.h>
- (void)initCurrentHome {
// Registers the protocol to be implemented.
[[TuyaSmartBizCore sharedInstance] registerService:@protocol(TYSmartHomeDataProtocol) withInstance:self];
}
// Implements the protocol method.
- (TuyaSmartHome *)getCurrentHome {
TuyaSmartHome *home = [TuyaSmartHome homeWithHomeId:@"Current home ID"];
return home;
}
Swift
import TuyaSmartDeviceKit
class TYActivatorTest: NSObject,TYSmartHomeDataProtocol{
func test() {
TuyaSmartBizCore.sharedInstance().registerService(TYSmartHomeDataProtocol.self, withInstance: self)
}
func getCurrentHome() -> TuyaSmartHome! {
let home = TuyaSmartHome.init(homeId: 111)
return home
}
}
Objective-C
id<TYPanelProtocol> impl = [[TuyaSmartBizCore sharedInstance] serviceOfProtocol:@protocol(TYPanelProtocol)];
[impl cleanPanelCache];
Swift
let impl = TuyaSmartBizCore.sharedInstance().service(of: TYPanelProtocol.self) as? TYPanelProtocol
impl?.cleanPanelCache()
Objective-C
id<TYPanelProtocol> impl = [[TuyaSmartBizCore sharedInstance] serviceOfProtocol:@protocol(TYPanelProtocol)];
// Returns the panel view controller and enables automatic navigation.
if (deviceModel) {
[impl getPanelViewControllerWithDeviceModel:deviceModel initialProps:nil contextProps:nil completionHandler:^(__kindof UIViewController * _Nullable panelViewController, NSError * _Nullable error) {
}];
} else if (groupModel) {
[impl getPanelViewControllerWithGroupModel:groupModel initialProps:nil contextProps:nil completionHandler:^(__kindof UIViewController * _Nullable panelViewController, NSError * _Nullable error) {
}];
}
Swift
let impl = TuyaSmartBizCore.sharedInstance().service(of: TYPanelProtocol.self) as? TYPanelProtocol
// Returns the panel view controller and enables automatic navigation.
impl?.getPanelViewController(with: deviceModel, initialProps: nil, contextProps: nil, completionHandler: { (vc, err) in
})
impl?.getPanelViewController(with: groupModel, initialProps: nil, contextProps: nil, completionHandler: { (vc, err) in
})
Is this page helpful?
YesFeedbackIs this page helpful?
YesFeedback