Migrate IPC UI BizBundles

Last Updated on : 2023-05-22 06:38:32download

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 "TuyaSmartHomeKit"
  # Adds Device Control UI BizBundle with a specified version number.
  pod 'TuyaSmartPanelBizBundle', 'xxx'
  # Adds the IPC Panel BizBundle.
  pod 'TuyaSmartCameraPanelBizBundle', 'xxx'
  # Adds the IPC RN Panel BizBundle if an IPC RN page is required.
  pod 'TuyaSmartCameraRNPanelBizBundle', '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 TuyaSmartCameraPanelBizBundle 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<TYPanelProtocol> impl = [[TuyaSmartBizCore sharedInstance] serviceOfProtocol:@protocol(TYPanelProtocol)];
    [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:

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

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

    [[TuyaSmartBizCore sharedInstance] registerService:@protocol(TYCameraProtocol) withInstance:self];
    
    #pragma mark - TYCameraProtocol
    
    - (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<TYCameraProtocol> impl = [[TuyaSmartBizCore sharedInstance] serviceOfProtocol:@protocol(TYCameraProtocol)];
    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.