使用iOS hue SDK从色调设置创建和删除组

时间:2014-02-20 13:51:42

标签: ios philips-hue

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

我使用的是飞利浦色调iOS SDK。

1 个答案:

答案 0 :(得分:3)

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