English
English
简体中文
Contact Us
Register
Log In

Group Management UI BizBundle

Last Updated on : 2022-10-12 10:52:38download

Group Management UI BizBundle provides the service logic and UI encapsulation for device groups. This allows users to create device groups, and control multiple devices of the same group in each request. You can use the UI BizBundle to implement multiple features. For example, create a group of devices that belong to the same type, and add devices to or delete them from groups. Currently, only common and standard groups of Wi-Fi devices can be created and modified.

Integrate with the UI BizBundle

Add the components of the Group Management UI BizBundle to the Podfile and run the command pod update.

source "https://github.com/tuya/tuya-pod-specs"
source 'https://cdn.cocoapods.org/'
platform :ios, '11.0'

target 'your_target_name' do
  # Adds the Group Management UI BizBundle
  pod 'TuyaSmartGroupHandleBizBundle'
end

Service protocols

Provide services

The UI BizBundle relies on the implementation of the protocol TYGroupHandleProtocol to provide services. In the TYModuleServices component, you can view the TYGroupHandleProtocol.h file and navigate to TYGroupHandlePlugAPI.h. The following code block shows the protocol content:

```objc
typedef enum {
TYGroupHandleTypeSupport,
TYGroupHandleTypeNotSupport,
TYGroupHandleTypeInvalid,
} TYGroupHandleType;

@protocol TYGroupHandleProtocol <NSObject>
/**

zh^
创建 Wi-Fi 标准或普通群组
zh$

en^
Create standard or common Wi-Fi groups.
en$

@param deviceId zh^  设备 ID zh$ en^ device ID en$
@param completion zh^ 回调 zh$ en^ call back en$
*/
- (void)createWifiGroupWithDeviceId:(NSString *_Nonnull)deviceId completion:(void (^ _Nullable)(TYGroupHandleType type))completion
__deprecated_msg("Use createGroup:completion: instead");

/**

zh^
编辑 Wi-Fi 标准或普通群组
zh$

en^
Modify standard or common Wi-Fi groups.
en$

@param groupId zh^  群组 ID zh$ en^ group ID en$
@param completion zh^ 回调 zh$ en^ call back en$
*/
- (void)editWifiGroupWithGroupId:(NSString *_Nonnull)groupId completion:(void (^ _Nullable)(TYGroupHandleType type))completion
__deprecated_msg("Use editGroup:completion: instead");

/**

zh^
创建群组。
zh$

en^
Create standard or common Wi-Fi groups.
en$

@param deviceId zh^ 设备ID zh$ en^ device ID en$
@param completion zh^ 回调 zh$ en^ call back en$
*/
- (void)createGroup:(NSString *_Nonnull)deviceId completion:(void (^ _Nullable)(TYGroupHandleType type))completion;

/**

zh^
编辑群组
zh$

en^
Modify standard or common Wi-Fi groups.
en$

@param groupId zh^ 群组ID zh$ en^ group ID en$
@param completion zh^ 回调 zh$ en^ call back en$
*/
- (void)editGroup:(NSString *_Nonnull)groupId completion:(void (^ _Nullable)(TYGroupHandleType type))completion;


@end
```

Depend on services

The UI BizBundle depends on the method provided by the protocol TYFamilyProtocol. Before you call the UI BizBundle, you must implement the protocol TYFamilyProtocol to provide the current home information required by the scene component.

Usage instruction

Things to note

  • Before the call of any API method, make sure that the user has logged in to the app.

Create a group

ObjC:

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

- (void)createGroup:(NSString *)deviceId completion:(void (^)(TYGroupHandleType type))completion{
    id <TYGroupHandleProtocol> impl = [[TuyaSmartBizCore sharedInstance] serviceOfProtocol:@protocol(TYGroupHandleProtocol)];
    [impl createGroup:deviceId completion:^(TYGroupHandleType type) {
        switch (type) {
            case TYGroupHandleTypeInvalid:
                NSLog(@"DeviceId is invalid");
                break;
            case TYGroupHandleTypeSupport:
                NSLog(@"Support");
                break;
            case TYGroupHandleTypeNotSupport:
                NSLog(@"Not Support");
                break;
            default:
                break;
        }
    }];
}

Swift:

func createGroup(deviceId: String, completion: @escaping (TYGroupHandleType) -> Void) {
        let groupImpl = TuyaSmartBizCore.sharedInstance().service(of: TYGroupHandleProtocol.self) as? TYGroupHandleProtocol
        groupImpl?.createGroup(deviceId, completion: { (type) in
            switch type {
               case TYGroupHandleTypeInvalid  :
                    print("DeviceId is invalid")
                    break
               case TYGroupHandleTypeSupport  :
                    print("Support")
                    break
               case TYGroupHandleTypeNotSupport  :
                    print("NotSupport")
                    break
               default :
                    break
            }
        })
    }

Modify a group

ObjC:

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

- (void)editGroup:(NSString *)groupId completion:(void (^)(TYGroupHandleType type))completion;{
    id <TYGroupHandleProtocol> impl = [[TuyaSmartBizCore sharedInstance] serviceOfProtocol:@protocol(TYGroupHandleProtocol)];
    [impl editGroup:groupId completion:^(TYGroupHandleType type) {
        switch (type) {
            case TYGroupHandleTypeInvalid:
                NSLog(@"DeviceId is invalid");
                break;
            case TYGroupHandleTypeSupport:
                NSLog(@"Support");
                break;
            case TYGroupHandleTypeNotSupport:
                NSLog(@"Not Support");
                break;
            default:
                break;
        }
    }];
}

Swift:

    func editGroup(groupId: String, completion: @escaping (TYGroupHandleType) -> Void) {
        let groupImpl = TuyaSmartBizCore.sharedInstance().service(of: TYGroupHandleProtocol.self) as? TYGroupHandleProtocol
        groupImpl?.editGroup(groupId, completion: { (type) in
            switch type {
               case TYGroupHandleTypeInvalid  :
                    print("DeviceId is invalid")
                    break
               case TYGroupHandleTypeSupport  :
                    print("Support")
                    break
               case TYGroupHandleTypeNotSupport  :
                    print("NotSupport")
                    break
               default :
                    break
            }
        })
    }