0

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

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

4

1 回答 1

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
    // ...
}];
于 2014-02-21T17:51:24.997 回答