更新时间:2022-06-23 09:23:24下载pdf
涂鸦 智慧居住 设备详情 UI 业务包包含了以下功能:
在工程的 Podfile 文件中添加业务包组件,并执行 pod update
命令。
source "https://github.com/tuya/TuyaPublicSpecs.git"
source 'https://cdn.cocoapods.org/'
target 'your_target_name' do
# TuyaSmartResidence SDK
pod "TuyaSmartResidenceKit"
# 添加设备详情 UI 业务包
pod 'TuyaSmartResidenceDeviceDetailBizBundle'
end
设备详情 UI 业务包涉及到设备图标上传时,需要使用系统相册和相机权限。因此,会涉及到部分苹果隐私权限的声明。您需要在工程的 info.plist
中添加如下权限声明:
<!-- 相册 -->
<key>NSPhotoLibraryUsageDescription</key>
<string>App 需要您的同意,才能访问相册</string>
<!-- 相机 -->
<key>NSCameraUsageDescription</key>
<string>App 需要您的同意,才能访问相机</string>
在主工程中,新建 configList.json
文件。如果已经存在该文件,则不用再新建。configList.json
配置文件内容大致如下:
{
"deviceDetail": [{"type": "header"}],
"其他配置页面 key":[xxxxx]
}
在 configList.json
中添加以下内容:
deviceDetail
[
{
"type": "header"
},
{
"type": "device_info"
},
{
"type": "net_setting"
},
{
"type": "section_off_line_warn"
},
{
"type": "off_line_warn"
},
{
"type": "section_other"
},
{
"type": "group_edit_devices"
},
{
"type": "group_create"
},
{
"type": "help_and_feedback"
},
{
"type": "check_device_network"
},
{
"type": "check_firmware_update"
},
{
"type": "empty",
"height":16
},
{
"type": "footer"
}
]
自定义设备详情。
deviceDetail
数组 item
的顺序影响设备详情页 item
展示的顺序。如果移除 item
,则相应地移除设备详情页子功能。
deviceDetail 类型 |
设备详情页子功能 |
---|---|
header | 查看修改设备图标,名称,位置 |
device_info | 设备信息 |
net_setting | 设备备用网络 |
off_line_warn | 设备离线提醒 |
group_edit_devices | 编辑群组 |
group_create | 创建群组 |
footer | 移除设备 |
section_other | 分区头,无实际设备功能 |
empty | 空 view ,无实际设备功能 |
调用 UI 业务包逻辑前,请确保该站点调用过以下方法:
[self.site fetchSiteDetailWithSuccess:^(TuyaResidenceSiteModel * _Nonnull siteModel) {
} failure:^(NSError *error) {
}];
然后实现 TYFamilyProtocol
中的协议方法currentFamilyId
。
#import <TuyaSmartBizCore/TuyaSmartBizCore.h>
#import <TYModuleServices/TYFamilyProtocol.h>
- (void)initCurrentSite {
// 注册要实现的协议
[[TuyaSmartBizCore sharedInstance] registerService:@protocol(TYFamilyProtocol) withInstance:self];
}
// 实现对应的协议方法
- (long long)currentFamilyId {
return @"site id";
}
群组创建和编辑属于可选功能,您需要需要额外接入 设备群组 UI 业务包。
方法 | 参数 |
---|---|
跳转到网络检测页 | 设备 ID |
跳转到设备详情页,以 Push 方式实现 | TuyaSmartDeviceModel/TuyaSmartGroupModel |
#import <TuyaSmartBizCore/TuyaSmartBizCore.h>
#import <TYModuleServices/TuyaSmartResidenceDeviceDetailProtocol.h>
id<TuyaSmartResidenceDeviceDetailProtocol> impl = [[TuyaSmartBizCore sharedInstance] serviceOfProtocol:@protocol(TuyaSmartResidenceDeviceDetailProtocol)];
// 跳转到设备网络检测页
[impl gotoDeviceDetailNetworkViewControllerWithDeviceId:@"设备 id"];
// 如果是设备
TuyaSmartDevice *device = [TuyaSmartDevice deviceWithDeviceId:@"设备 id"];
[impl gotoDetailViewControllerWithDevice:device.deviceModel group:nil];
// 如果是群组
TuyaSmartGroup *group = [TuyaSmartDevice groupWithGroupId:@"群组 id"];
[impl gotoDetailViewControllerWithDevice:nil group:group.deviceModel];
自定义子功能可以通过配置 configList.json
来实现。在 configList.json
文件的 deviceDetail
插入自定义 type
。
type
值必须以 c_
开头。例如,插入 c_test_insert
、c_test_async_insert
。
{
"deviceDetail": [
{
"type": "c_test_insert"
},
{
"type": "c_test_async_insert"
},
{
"type": "header"
},
{
"type": "device_info"
},
{
"type": "net_setting"
},
{
"type": "section_off_line_warn"
},
{
"type": "off_line_warn"
},
{
"type": "section_other"
},
{
"type": "help_and_feedback"
},
{
"type": "check_device_network"
},
{
"type": "check_firmware_update"
},
{
"type": "empty",
"height":16
},
{
"type": "footer"
}
]
}
/// Synchronize callbacks for item insertion
/// @param block Synchronous handling of item insertion callbacks
- (void)insertMenuItem:(ResidenceInsertMenuItemBlock)block;
//@param type type added by configList.json
//@param device device model
//@param group The group model. Determines if the device is a group or not, based on whether the group is nil
//@return An object that complies with the TuyaSmartResidenceDeviceDetailCustomMenuModel protocol. If nil is returned, the item of this type will not be displayed
typedef id<TuyaSmartResidenceDeviceDetailCustomMenuModel> _Nullable (^ResidenceInsertMenuItemBlock)(NSString * _Nonnull type, TuyaSmartDeviceModel * _Nullable device, TuyaSmartGroupModel * _Nullable group);
/// Asynchronous callback for item insertion
/// @param block Callback for asynchronous handling of item insertion
- (void)insertMenuItemAsync:(ResidenceInsertMenuItemAsyncBlock)block;
// Asynchronously process the item insertion, call complete() when the asynchronous operation is finished, call back the data to the device details and refresh the list. Determine if the device is a group or not based on whether the group is nil
typedef void (^ResidenceInsertMenuItemAsyncBlock)(NSString * _Nonnull type, TuyaSmartDeviceModel * _Nullable device, TuyaSmartGroupModel * _Nullable group, ResidenceInsertMenuItemComplete _Nonnull complete);
//自定义一个类遵守 TuyaSmartResidenceDeviceDetailCustomMenuModel 协议
@interface CustomMenuModel : NSObject<TuyaSmartResidenceDeviceDetailCustomMenuModel>
///标题
@property (nonatomic,copy) NSString *title;
///子标题
@property (nonatomic,copy) NSString *detail;
@end
@implementation CustomMenuModel
@end
id<TuyaSmartResidenceDeviceDetailProtocol> impl = [[TuyaSmartBizCore sharedInstance] serviceOfProtocol:@protocol(TuyaSmartResidenceDeviceDetailProtocol)];
[impl insertMenuItem:^ id<TuyaSmartResidenceDeviceDetailCustomMenuModel> (NSString * _Nonnull type, TuyaSmartDeviceModel * _Nonnull device, TuyaSmartGroupModel * _Nonnull group) {
if ([type isEqualToString:@"c_test_insert"]) {
CustomMenuModel *model = [CustomMenuModel new];
if (group) { // 根据 group 是否为 nil,来判断获取到的是设备还是群组
model.title = type;
model.detail = @"group";
}
else {
model.title = type;
model.detail = @"device";
}
return model;
}
return nil;
}];
[impl insertMenuItemAsync:^(NSString * _Nonnull type, TuyaSmartDeviceModel * _Nullable device, TuyaSmartGroupModel * _Nullable group, ResidenceInsertMenuItemComplete _Nonnull complete) {
if ([type isEqualToString:@"c_test_async_insert"]) {
// 耗时操作
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
CustomMenuModel *model = [CustomMenuModel new];
if (group) { // 根据 group 是否为 nil,来判断获取到的是设备还是群组
model.title = type;
model.detail = @"group";
}
else {
model.title = type;
model.detail = @"device";
}
complete(model);
});
}
}];
id<TuyaSmartResidenceDeviceDetailProtocol> impl = [[TuyaSmartBizCore sharedInstance] serviceOfProtocol:@protocol(TuyaSmartResidenceDeviceDetailProtocol)];
[impl clickMenuItem: ^(NSString * _Nonnull type, TuyaSmartDeviceModel * _Nullable device ,TuyaSmartGroupModel * _Nullable group) {
NSLog(@"clickItem: type:%@",type);
}];
该内容对您有帮助吗?
是意见反馈该内容对您有帮助吗?
是意见反馈