Is this page helpful?
YesNoLast Updated on : 2022-03-01 08:32:58download
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.
Add the components of the Group Management UI BizBundle to the Podfile
and run the command pod update
.
source "https://github.com/TuyaInc/TuyaPublicSpecs.git"
source 'https://cdn.cocoapods.org/'
target 'your_target_name' do
# Adds the Group Management UI BizBundle
pod 'TuyaSmartGroupHandleBizBundle', '~> 3.22.0'
end
The UI BizBundle relies on the implementation of the protocol TYGroupHandleProtocol
to provide services. You can view the TYGroupHandleProtocol.h
file in the TYModuleServices
component.
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^ Callback en$
*/
- (void)createWifiGroupWithDeviceId:(NSString *_Nonnull)deviceId completion:(void (^ _Nullable)(TYGroupHandleType type))completion;
/**
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^ Callback en$
*/
- (void)editWifiGroupWithGroupId:(NSString *_Nonnull)groupId completion:(void (^ _Nullable)(TYGroupHandleType type))completion;
@end
The UI BizBundle depends on the method provided by the protocol TYSmartHomeDataProtocol
. The protocol TYSmartHomeDataProtocol
must be implemented before the UI BizBundle is called to provide the required home information.
/**
Returns the current home. If the current user does not have a home, `nil` is returned.
@return TuyaSmartHome
*/
- (TuyaSmartHome *)getCurrentHome;
Before the call of any API method, make sure that the user has logged in to the app.
Before the UI BizBundle is used, the getCurrentHome
method provided by the protocol TYSmartHomeDataProtocol
must be implemented first.
ObjC:
#import <TuyaSmartBizCore/TuyaSmartBizCore.h>
#import <TYModuleServices/TYSmartHomeDataProtocol.h>
- (void)initCurrentHome {
// Registers the protocols to be implemented.
[[TuyaSmartBizCore sharedInstance] registerService:@protocol(TYSmartHomeDataProtocol) withInstance:self];
}
// Implements the protocol method.
- (TuyaSmartHome *)getCurrentHome {
TuyaSmartHome *home = [TuyaSmartHome homeWithHomeId:@" Current home ID"];
return home;
}
Swift:
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
}
}
ObjC:
#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
}
})
}
ObjC:
#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
}
})
}
Is this page helpful?
YesNoIs this page helpful?
YesNo