簡體   English   中英

使用iOS hue SDK在hue設置中創建和刪除組

[英]Creating and removing groups from hue setup with iOS hue SDK

我正在尋找一種從色相橋中創建和刪除組( PHGroup類)的方法。 讀取現有組並不困難,只需讀取所有數據的緩存即可。 但是如何刪除或添加新組到該組集合?

我正在使用Philips 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
    // ...
}];

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM