Device Control UI BizBundle

Last Updated on : 2022-03-03 06:52:12download

Device Control UI BizBundle is the core container of the control panel for each Powered by Tuya (PBT) device. Based on Tuya Smart Residence App SDK for iOS, the UI BizBundle encapsulates the APIs to load and control panels and accelerates the application development process.

Functional description

The following features are supported:

  • Panel loading: supports panels of multiple protocols, such as Wi-Fi, Zigbee, Bluetooth mesh, and Bluetooth.
  • Device control: controls a single device and device groups. Device groups cannot be managed.
  • Scheduled tasks: configures scheduled tasks for specific devices.

Integrate with the UI BizBundle

Add the components of the Device Control UI BizBundle to the Podfile and run the command pod update.

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

target 'your_target_name' do
  # TuyaSmartResidence SDK
  pod "TuyaSmartResidenceKit"
  # Adds the UI BizBundle.
  pod 'TuyaSmartResidencePanelBizBundle'
  # Depends on the robot vacuum plug-ins to integrate with their features if needed.
  # pod 'TuyaRNApi/Sweeper'
end

Things to note

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 React Native has been integrated and its version is later than v0.59.10, the UI BizBundle cannot be integrated due to version incompatibility.
    • If React Native has been integrated and its version is later than v0.51 and equal to or earlier than v0.59.10, the Tuya panels cannot be accessed as expected due to the repeated uses of the React Native library. Use either of the following methods to troubleshoot the problem:
      1. Remove React Native from your iOS project and use React Native v0.59.10 that the UI BizBundle depends on.
      2. Rename React Native that is integrated with your iOS project to avoid the repeated React Native library.

    If both methods failed, the UI BizBundle cannot be integrated.

Permissions

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
    

Implement service protocols

Provide services

The UI BizBundle relies on the implementation of the protocol TuyaSmartResidencePanelProtocol to provide services. You can view the TuyaSmartResidencePanelProtocol.h file in the TYModuleServices component.

#import <TuyaSmartBizCore/TuyaSmartBizCore.h>
#import <TYModuleServices/TuyaSmartResidencePanelProtocol.h>

// 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;

Depend on services

This UI BizBundle is used to load devices and implement features of different devices. For this purpose, implement the following dependent protocols:

  • TuyaSmartResidenceDeviceDetailProtocol: 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;
    
  • TuyaSmartResidenceGroupHandleProtocol: 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.
    
    @param query The initial data.
    @param Specifies whether to present by using the `navigator` method.
    @param success
    @param failure
    */
    - (void)presentMeshLocalGroupWithQueryData:(NSDictionary *)query
                                     isNav:(BOOL)isNav;
    

Usage instruction

Things to note

  • Before the UI BizBundle is called, the following method must be implemented for the site:

    [self.site fetchSiteDetailWithSuccess:^(TuyaResidenceSiteModel * _Nonnull siteModel) {
    
    } failure:^(NSError *error) {
    
    }];
    
  • Then, implement the protocol method currentFamilyId in TYFamilyProtocol.

    #import <TuyaSmartBizCore/TuyaSmartBizCore.h>
    #import <TYModuleServices/TYFamilyProtocol.h>
    
    - (void)initCurrentSite {
    	// Registers the protocol to be implemented.
    	[[TuyaSmartBizCore sharedInstance] registerService:@protocol(TYFamilyProtocol) withInstance:self];
    }
    
    // Implements the target protocol method.
    - (long long)currentFamilyId {
    	return @"site id";
    }
    

Clear cached data of the panel

id<TuyaSmartResidencePanelProtocol> impl = [[TuyaSmartBizCore sharedInstance] serviceOfProtocol:@protocol(TuyaSmartResidencePanelProtocol)];
[impl cleanPanelCache];

Open the panel

id<TuyaSmartResidencePanelProtocol> impl = [[TuyaSmartBizCore sharedInstance] serviceOfProtocol:@protocol(TuyaSmartResidencePanelProtocol)];
// 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) {
        [self.navigationController pushViewController:panelViewController animated:YES];
    }];
} else if (groupModel) {
    [impl getPanelViewControllerWithGroupModel:groupModel initialProps:nil contextProps:nil completionHandler:^(__kindof UIViewController * _Nullable panelViewController, NSError * _Nullable error) {
        [self.navigationController pushViewController:panelViewController animated:YES];
    }];
}