简体中文
简体中文
English
联系我们
注册
登录
layout空间导航

设备群组 UI 业务包

更新时间:2021-12-25 01:40:41下载pdf

涂鸦设备群组 UI 业务包功能封装了群组业务逻辑和 UI 界面,创建群组后可以同时控制群组内的设备。业务逻辑包括创建相同设备类型的群组、添加群组设备、删除群组设备等。目前,仅支持创建和编辑 Wi-Fi 普通群组和 Wi-Fi 标准群组。

接入组件

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

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

target 'your_target_name' do
  # 添加设备群组 UI 业务包
  pod 'TuyaSmartGroupHandleBizBundle', '~> 3.22.0'
end

服务协议

提供服务

UI 业务包实现 TYGroupHandleProtocol 协议以提供对外服务。在 TYModuleServices 组件中查看 TYGroupHandleProtocol.h 协议文件内容为:

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

@protocol TYGroupHandleProtocol <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)(TYGroupHandleType type))completion;

/**

 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)(TYGroupHandleType type))completion;

@end

依赖服务

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

/**
 获取当前的家庭,当前没有家庭的时候, 返回 nil。

 @return TuyaSmartHome
 */
- (TuyaSmartHome *)getCurrentHome;

使用指南

注意事项

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

  • 调用业务包逻辑前,要先实现 TYSmartHomeDataProtocol 中的协议方法getCurrentHome

    Objective-C 示例

    #import <TuyaSmartBizCore/TuyaSmartBizCore.h>
    #import <TYModuleServices/TYSmartHomeDataProtocol.h>
    
    - (void)initCurrentHome {
    	// 注册要实现的协议
    	[[TuyaSmartBizCore sharedInstance] registerService:@protocol(TYSmartHomeDataProtocol) withInstance:self];
    }
    
    // 实现对应的协议方法
    - (TuyaSmartHome *)getCurrentHome {
    	TuyaSmartHome *home = [TuyaSmartHome homeWithHomeId:@" 当前家庭 id"];
    	return home;
    }
    

    Swfit 示例

    import TuyaSmartDeviceKit
    
    class TYMessageCenterTest: NSObject,TYSmartHomeDataProtocol{
    
    
    	func test() {
    		TuyaSmartBizCore.sharedInstance().registerService(TYSmartHomeDataProtocol.self, withInstance: self)
    	}
    
    	func getCurrentHome() -> TuyaSmartHome! {
    		let home = TuyaSmartHome.init(homeId: 111)
    		return home
    	}
    
    }
    

创建群组

Objective-C 示例

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

- (void)createWifiGroupWithDeviceId:(NSString *)deviceId completion:(void (^)(TYGroupHandleType type))completion{
    id <TYGroupHandleProtocol> impl = [[TuyaSmartBizCore sharedInstance] serviceOfProtocol:@protocol(TYGroupHandleProtocol)];
    [impl createWifiGroupWithDeviceId: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 createWifiGroup(withDeviceId deviceId: String, completion: @escaping (TYGroupHandleType) -> Void) {
        let groupImpl = TuyaSmartBizCore.sharedInstance().service(of: TYGroupHandleProtocol.self) as? TYGroupHandleProtocol
        groupImpl?.createWifiGroup(withDeviceId: 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
            }
        })
    }

编辑群组

Objective-C 示例

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

- (void)editWifiGroupWithGroupId:(NSString *)groupId completion:(void (^)(TYGroupHandleType type))completion;{
    id <TYGroupHandleProtocol> impl = [[TuyaSmartBizCore sharedInstance] serviceOfProtocol:@protocol(TYGroupHandleProtocol)];
    [impl editWifiGroupWithGroupId: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 editWifiGroup(withGroupId groupId: String, completion: @escaping (TYGroupHandleType) -> Void) {
        let groupImpl = TuyaSmartBizCore.sharedInstance().service(of: TYGroupHandleProtocol.self) as? TYGroupHandleProtocol
        groupImpl?.editWifiGroup(withGroupId: 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
            }
        })
    }