【问题标题】:Creating and removing groups from hue setup with iOS hue SDK使用 iOS 色调 SDK 从色调设置中创建和删除组
【发布时间】:2014-02-20 13:51:42
【问题描述】:

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

我正在使用 Philips hue iOS SDK。

【问题讨论】:

  • 嗨..我在实施 HUE 时遇到问题..你能帮帮我吗
  • @RahulMishra 打开一个带有“philips-hue”标签的问题。

标签: ios philips-hue


【解决方案1】:

可以使用 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
    // ...
}];

【讨论】:

  • 我看到缓存没有立即更新。有没有办法强制 Bridge Cache 更新?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多