Browsing States

The thing will periodically upload its state to the Kii Cloud. You can browse these states from the mobile application. See here for the overview.

You can get the latest state based on the design made in the Schema Definition. For example, you can get the following JSON for our "air conditioner" sample scenario shown in the schema definition page.

{
  "power" : true,
  "presetTemperature" : 25,
  "fanspeed" : 5,
  "currentTemperature" : 28,
  "currentHumidity" : 65
}

The following sample code shows how you can read the latest state.

Prior to the execution, you need to get an ThingIFAPI instance (api) that is initialized by the steps described in Initializing and Onboarding.

// Get the thing state.
api.getState() { (result: Dictionary<String, AnyObject>?, error: ThingIFError?) -> Void in
  if error != nil {
    // Handle the error.
    return
  }
  for (key, value) in result! {
    // Do something with the state.
  }
}

By executing the getState method, you can get the Dictionary that correspond to the state's JSON from the callback. In the above JSON example, you will get power and presetTemperature as the Dictionary keys and true and 25 as the values.

You cannot query or browse state history via Thing-IF SDK for iOS. Please use either REST API or developer portal.