Saving and Restoring the Initialized Information

If you need to save the ThingIFAPI instance for a long time, you can use the serialization feature to save it in the storage (i.e., iOS's NSUserDefaults).

Saving the instance to the storage is automatically made by the SDK.

After the process relaunched, you can restore the instance as follows:

var api:ThingIFAPI?

do {
  // Load a Thing-IF API.
  try api = ThingIFAPI.loadWithStoredInstance()
} catch ThingIFError.API_NOT_STORED {
  // Handle the error.
} catch {
  // Handle the error.
}

If you've created multiple ThingIFAPI instances with dedicated tags, you can specify the instance to restore with its tag. Simply pass the tag name in the argument of the loadFromStoredInstance method. See Initialize Thing-IF SDK to learn more about the tag.

You can delete the preserved instance with the removeStoredInstance method. Please refer to the reference for more details.

When saving to the NSUserDefaults, we use the key names ThingIFAPI_INSTANCE or ThingIFAPI_INSTANCE_tag name. All information previously stored with these keys will be overwritten.