设备群组 UI 业务包

更新时间:2024-06-03 03:41:06下载pdf

涂鸦设备群组 UI 业务包功能封装了群组业务逻辑和 UI 界面,创建群组后可以同时控制群组内的设备。业务逻辑包括创建相同设备类型的群组、添加群组设备、删除群组设备等。

接入组件

在工程的 Podfile 文件中添加群组业务包组件,并执行 pod update 命令:

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

target 'your_target_name' do
  # 添加设备群组 UI 业务包
  pod 'ThingSmartGroupHandleBizBundle'
end

服务协议

提供服务

UI 业务包实现 ThingGroupHandleProtocol 协议以提供对外服务。在 ThingModuleServices 组件中查看 ThingGroupHandleProtocol.h,链接至 ThingGroupHandlePlugAPI.h,协议文件内容为:

 typedef enum {
 ThingGroupHandleTypeSupport,
 ThingGroupHandleTypeNotSupport,
 ThingGroupHandleTypeInvalid,
 } ThingGroupHandleType;

 @protocol ThingGroupHandleProtocol <NSObject>
 /**

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

 en^
 Create wifi standard or common group
 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)(ThingGroupHandleType type))completion
 __deprecated_msg("Use createGroup:completion: instead");

 /**

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

 en^
 Edit wifi standard or common group
 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)(ThingGroupHandleType type))completion
 __deprecated_msg("Use editGroup:completion: instead");

 /**

 zh^
 创建群组。
 zh$

 en^
 Create wifi standard or common group
 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)(ThingGroupHandleType type))completion;

 /**

 zh^
 编辑群组
 zh$

 en^
 Edit wifi standard or common group
 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)(ThingGroupHandleType type))completion;


 @end

依赖服务

UI 业务包正常运行需要依赖 ThingFamilyProtocol 这个协议提供的协议方法。调用业务包之前,您需要实现 ThingFamilyProtocol 协议,来提供场景组件所需的当前家庭信息。

使用指南

注意事项

调用任何接口之前,请务必确认用户已登录。

创建群组

Objective-C 示例

#import <ThingSmartBizCore/ThingSmartBizCore.h>
#import <ThingModuleServices/ThingGroupHandleProtocol.h>

- (void)createGroup:(NSString *)deviceId completion:(void (^)(ThingGroupHandleType type))completion{
    id <ThingGroupHandleProtocol> impl = [[ThingSmartBizCore sharedInstance] serviceOfProtocol:@protocol(ThingGroupHandleProtocol)];
    [impl createGroup:deviceId completion:^(ThingGroupHandleType type) {
        switch (type) {
            case ThingGroupHandleTypeInvalid:
                NSLog(@"DeviceId is invalid");
                break;
            case ThingGroupHandleTypeSupport:
                NSLog(@"Support");
                break;
            case ThingGroupHandleTypeNotSupport:
                NSLog(@"Not Support");
                break;
            default:
                break;
        }
    }];
}

Swift 示例

func createGroup(deviceId: String, completion: @escaping (ThingGroupHandleType) -> Void) {
        let groupImpl = ThingSmartBizCore.sharedInstance().service(of: ThingGroupHandleProtocol.self) as? ThingGroupHandleProtocol
        groupImpl?.createGroup(deviceId, completion: { (type) in
            switch type {
               case ThingGroupHandleTypeInvalid  :
                    print("DeviceId is invalid")
                    break
               case ThingGroupHandleTypeSupport  :
                    print("Support")
                    break
               case ThingGroupHandleTypeNotSupport  :
                    print("NotSupport")
                    break
               default :
                    break
            }
        })
    }

编辑群组

Objective-C 示例

#import <ThingSmartBizCore/ThingSmartBizCore.h>
#import <ThingModuleServices/ThingGroupHandleProtocol.h>

- (void)editGroup:(NSString *)groupId completion:(void (^)(ThingGroupHandleType type))completion;{
    id <ThingGroupHandleProtocol> impl = [[ThingSmartBizCore sharedInstance] serviceOfProtocol:@protocol(ThingGroupHandleProtocol)];
    [impl editGroup:groupId completion:^(ThingGroupHandleType type) {
        switch (type) {
            case ThingGroupHandleTypeInvalid:
                NSLog(@"DeviceId is invalid");
                break;
            case ThingGroupHandleTypeSupport:
                NSLog(@"Support");
                break;
            case ThingGroupHandleTypeNotSupport:
                NSLog(@"Not Support");
                break;
            default:
                break;
        }
    }];
}

Swift 示例

    func editGroup(groupId: String, completion: @escaping (ThingGroupHandleType) -> Void) {
        let groupImpl = ThingSmartBizCore.sharedInstance().service(of: ThingGroupHandleProtocol.self) as? ThingGroupHandleProtocol
        groupImpl?.editGroup(groupId, completion: { (type) in
            switch type {
               case ThingGroupHandleTypeInvalid  :
                    print("DeviceId is invalid")
                    break
               case ThingGroupHandleTypeSupport  :
                    print("Support")
                    break
               case ThingGroupHandleTypeNotSupport  :
                    print("NotSupport")
                    break
               default :
                    break
            }
        })
    }