gpt4 book ai didi

ios - 使用 iOS hue SDK 从 hue 设置中创建和删除组

转载 作者:行者123 更新时间:2023-11-28 20:06:31 26 4
gpt4 key购买 nike

我正在寻找一种从 hue 桥中创建和删除组(PHGroup 类)的方法。读取现有组并不困难,只需读取缓存中的所有数据即可。但是,我该如何删除或向该群组集合中添加新群组?

我正在使用飞利浦 hue iOS SDK。

最佳答案

可以使用 PHBridgeSendAPI 类来管理组,该类包含管理桥资源(如组、场景、灯光等)的所有方法。请参见下面的一些示例。

创建群组

PHBridgeSendAPI 引用:

/**
Creates a new Group of lights
@param name the name of the group
@param lightIds the array of light ids to group
@param completionHandler completionHandler for details of created group or error handling
*/
- (void)createGroupWithName:(NSString *)name lightIds:(NSArray *)lightIds completionHandler:(PHBridgeSendGroupCompletionHandler)completionHandler

代码示例:

id<PHBridgeSendAPI> bridgeSendAPI = [[[PHOverallFactory alloc] init] bridgeSendAPI];

NSArray *lightIdentifiers = @[@"1", @"2", @"3"];

[bridgeSendAPI createGroupWithName:@"group name" lightIds:lightIdentifiers completionHandler:^(NSString *groupIdentifier, NSArray *errors){
if (errors.count > 0) {
// Error handling
}
else {
// Get group object from the cache
PHBridgeResourcesCache *cache = [PHBridgeResourcesReader readBridgeResourcesCache];

PHGroup *group = [cache.groups objectForKey:groupIdentifier];

// Other logic
// ...
}
}];


移除群组

PHBridgeSendAPI 引用:

/**  
Remote the group with the given identifier
@param groupIdentifier the identifier of the group to remove
@param completionHandler completionHandler for error handling
*/
- (void)removeGroupWithId:(NSString *)groupIdentifier completionHandler:(PHBridgeSendErrorArrayCompletionHandler)completionHandler;

代码示例:

id<PHBridgeSendAPI> bridgeSendAPI = [[[PHOverallFactory alloc] init] bridgeSendAPI];

// Remove the group
[bridgeSendAPI removeGroupWithId:@"Put here the group identifier you want to delete" completionHandler:^(NSArray *errors) {
if (errors.count > 0) {
// Error handling
}

// Other logic
// ...
}];

关于ios - 使用 iOS hue SDK 从 hue 设置中创建和删除组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21909832/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com