更新时间:2023-07-13 07:14:42下载pdf
涂鸦设备群组 UI 业务包功能封装了群组业务逻辑和 UI 界面,创建群组后可以同时控制群组内的设备。业务逻辑包括创建相同设备类型的群组、添加群组设备、删除群组设备等。
在工程的 Podfile
文件中添加群组业务包组件,并执行 pod update
命令:
source "https://github.com/tuya/tuya-private-specs"
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
,协议文件内容为:
```objc
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
}
})
}
该内容对您有帮助吗?
是意见反馈该内容对您有帮助吗?
是意见反馈