Migrate IPC UI BizBundles

Last Updated on : 2024-06-17 08:40:57download

IPC UI BizBundles can be integrated in multiple ways. They can be modularized to accelerate the integration. They can be migrated from an earlier version to the latest version of the IPC SDK. For more information, see IPC UI BizBundles.

Method 1: Migrate the integration method

Modify the references in the Podfile as described in the following code block:

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

target 'your_target_name' do
  # TuyaSmart SDK
  pod "ThingSmartHomeKit"
  # Adds Device Control UI BizBundle with a specified version number.
  pod 'ThingSmartPanelBizBundle', 'xxx'
  # Adds the IPC Panel BizBundle.
  pod 'ThingSmartCameraPanelBizBundle', 'xxx'
  # Adds the IPC RN Panel BizBundle if an IPC RN page is required.
  pod 'ThingSmartCameraRNPanelBizBundle', 'xxx'
end

Method 2: Migrate API methods

  • The earlier IPC SDK versions provide the class TuyaSmartCameraPanelSDK to implement the IPC control panel. The latest IPC UI BizBundles allow you to call API methods as modules of different IPC UI BizBundles.
  • The latest UI BizBundle ThingSmartCameraPanelBizBundle is incompatible with the legacy SDK TuyaSmartCameraPanelSDK. They cannot be integrated simultaneously.

Open IPC control panel

  • Legacy API call

    [TuyaSmartPanelSDK sharedInstance].homeId = deviceModel.homeId;
    [[TuyaSmartPanelSDK sharedInstance] gotoPanelViewControllerWithDevice:deviceModel completion:^(NSError *error) {
        NSLog(@"load error: %@", error);
    }];
    
  • Latest API call

    For more information, see Device Control UI BizBundle.

    id<ThingPanelProtocol> impl = [[ThingSmartBizCore sharedInstance] serviceOfProtocol:@protocol(ThingPanelProtocol)];
    [impl gotoPanelViewControllerWithDevice:deviceModel group:nil initialProps:nil contextProps:nil completion:^(NSError * _Nullable error) {
        if (error) {
            NSLog(@"Load error: %@", error);
        }
    }];
    

Callback for panel events

  • The legacy SDK provides TuyaSmartPanelSDKDelegate to execute the callback for panel events.
  • The latest version provides multiple protocols to execute the callback for different types of events.

If the panel container of the target device cannot be found, the following example shows the legacy API call:

#pragma mark - TuyaSmartPanelSDKDelegate

- (nullable UIViewController *)requireSpecialPanelForDevice:(nullable TuyaSmartDeviceModel *)device orGroup:(nullable TuyaSmartGroupModel *)group {

}

You can use the latest API call and provide a different protocol for each type of device. Example:

  • ThingRNCameraProtocol: IPC RN panel. You can implement this panel with your own methods, or integrate with the IPC Panel BizBundle ThingSmartCameraRNPanelBizBundle.

    [[ThingSmartBizCore sharedInstance] registerService:@protocol(ThingRNCameraProtocol) withInstance:self];
    
    #pragma mark - ThingRNCameraProtocol
    - (UIViewController *)cameraRNPanelViewControllerWithDeviceId:(NSString *)devId {
    
    }
    
  • ThingCameraProtocol: IPC native panel. You can implement this panel with your own methods, or integrate with the IPC Panel BizBundle ThingSmartCameraPanelBizBundle.

    [[ThingSmartBizCore sharedInstance] registerService:@protocol(ThingCameraProtocol) withInstance:self];
    
    #pragma mark - ThingCameraProtocol
    
    - (UIViewController *)viewControllerWithDeviceId:(NSString *)devId uiName:(NSString *)uiName {
    
    }
    

Get panel preview

  • Legacy API call

    #pragma mark - TuyaSmartCameraPanelSDK
    
    UIViewController *vc = [[TuyaSmartCameraPanelSDK sharedInstance] cameraViewControllerWithDeviceModel:deviceModel];
    [self.nav pushViewControllver:vc animated:YES];
    
  • Latest API call

    id<ThingCameraProtocol> impl = [[ThingSmartBizCore sharedInstance] serviceOfProtocol:@protocol(ThingCameraProtocol)];
    UIViewController *vc = [impl viewControllerWithDeviceId:self.deviceModel.devId uiName:self.device.uiName];
    [self.navigationController pushViewController:vc animated:YES];
    

You can also preview or navigate to other panels. For more information, see IPC UI BizBundles.