更新时间:2024-11-18 11:32:38
涂鸦设备群组 UI 业务包功能封装了群组业务逻辑和 UI 界面,创建群组后可以同时控制群组内的设备。业务逻辑包括创建相同设备类型的群组、添加群组设备、删除群组设备等。目前,仅支持创建和编辑 Wi-Fi 普通群组和 Wi-Fi 标准群组。
在工程的 Podfile
文件中添加群组业务包组件,并执行 pod update
命令:
source "https://github.com/tuya/tuya-pod-specs"
source 'https://cdn.cocoapods.org/'
platform :ios, '11.0'
target 'your_target_name' do
# 添加设备群组 UI 业务包
pod 'TuyaSmartGroupHandleBizBundle'
end
UI 业务包实现 TYGroupHandleProtocol
协议以提供对外服务。在 TYModuleServices
组件中查看 TYGroupHandleProtocol.h
,链接至 TYGroupHandlePlugAPI.h
,协议文件内容为:
```objc
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
__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)(TYGroupHandleType 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)(TYGroupHandleType 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)(TYGroupHandleType type))completion;
@end
```
UI 业务包正常运行需要依赖 TYFamilyProtocol
这个协议提供的协议方法。调用业务包之前,您需要实现 TYFamilyProtocol
协议,来提供场景组件所需的当前家庭信息。
Objective-C 示例
#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
}
})
}
Objective-C 示例
#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
}
})
}
该内容对您有帮助吗?
是意见反馈该内容对您有帮助吗?
是意见反馈