ThingIFAPI
open class ThingIFAPI: Equatable
Class provides API of the ThingIF.
-
Tag of the ThingIFAPI instance
Declaration
Swift
open let tag : String?
-
URL of KiiApps Server
Declaration
Swift
open var baseURL: String
-
The application ID found in your Kii developer console
Declaration
Swift
open var appID: String
-
The application key found in your Kii developer console
Declaration
Swift
open var appKey: String
-
Kii Cloud Application
Declaration
Swift
open let app: KiiApp
-
owner of target
Declaration
Swift
open let owner: Owner
-
Get installationID if the push is already installed. null will be returned if the push installation has not been done.
Declaration
Swift
open internal(set) var installationID: String?
Return Value
Installation ID used in IoT Cloud.
-
target
Declaration
Swift
open internal(set) var target: Target?
-
Checks whether on boarding is done.
Declaration
Swift
open var onboarded: Bool
-
Declaration
Swift
public static func == (left: ThingIFAPI, right: ThingIFAPI) -> Bool
Parameters
lhs
rhs
-
Try to load the instance of ThingIFAPI using stored serialized instance.
Instance is automatically saved when following methods are called. onboard, onboardWithVendorThingID, copyWithTarget and installPush has been successfully completed. (When copyWithTarget is called, only the copied instance is saved.)
If the ThingIFAPI instance is build without the tag, all instance is saved in same place and overwritten when the instance is saved.
If the ThingIFAPI instance is build with the tag(optional), tag is used as key to distinguish the storage area to save the instance. This would be useful to saving multiple instance.
When you catch exceptions, please call onload for saving or updating serialized instance.
Declaration
Swift
open static func loadWithStoredInstance( _ tag : String? = nil) throws -> ThingIFAPI?
Parameters
tag
tag of the ThingIFAPI instance
Return Value
ThingIFAPI instance.
-
Save this instance
Declaration
Swift
open func saveInstance() -> Void
-
Clear all saved instances in the NSiotUserDefaults.
Declaration
Swift
open static func removeAllStoredInstances()
-
Remove saved specified instance in the NSiotUserDefaults.
Declaration
Swift
open static func removeStoredInstances(_ tag : String? = nil) -> Void
Parameters
tag
tag of the ThingIFAPI instance or nil for default tag
-
Get new instance with new target
Declaration
Swift
open func copyWithTarget( _ newTarget: Target, tag : String? = nil) -> ThingIFAPI
Parameters
newTarget
target instance will be setted to new ThingIFAPI instance
tag
tag of the ThingIFAPI instance or nil for default tag
Return Value
New ThingIFAPI instance with newTarget
-
Query history states with trait alias.
Declaration
Swift
open func query( _ query: HistoryStatesQuery, completionHandler: @escaping ( [HistoryState]?, String?, ThingIFError?) -> Void) -> Void
-
Group history state
Declaration
Swift
open func query( _ query: GroupedHistoryStatesQuery, completionHandler: @escaping ( [GroupedHistoryStates]?, ThingIFError?) -> Void) -> Void
-
Aggregate history states
AggregatedValueType
represents type of calcuated value withAggregation.FunctionType
.- If the function is
Aggregation.FunctionType.max
,Aggregation.FunctionType.min
orAggregation.FunctionType.sum
, the type may be same as type of field represented byAggregation.FieldType
. - If the function is
Aggregation.FunctionType.mean
, the type may beDouble
. If the function is
Aggregation.FunctionType.count
, the type must beInt
.
Declaration
Swift
open func aggregate<AggregatedValueType>( _ query: GroupedHistoryStatesQuery, aggregation: Aggregation, completionHandler: @escaping( [AggregatedResult<AggregatedValueType>]?, ThingIFError?) -> Void) -> Void
- If the function is
-
Get the state of specified target.
Note: Please onboard first, or provide a target instance by calling copyWithTarget. Otherwise, KiiCloudError.TARGET_NOT_AVAILABLE will be return in completionHandler callback
Declaration
Swift
open func getTargetState( _ completionHandler:@escaping ([String : [String : Any]]?, ThingIFError?)-> Void) -> Void
-
Get the state of specified target by trait.
Note: Please onboard first, or provide a target instance by calling copyWithTarget. Otherwise, KiiCloudError.TARGET_NOT_AVAILABLE will be return in completionHandler callback
You can not use this method if You chose non trait verson.
Declaration
Swift
open func getTargetState( _ alias: String, completionHandler:@escaping ([String : Any]?, ThingIFError?)-> Void) -> Void
-
Onboard IoT Cloud with the specified thing ID. Specified thing will be owned by owner who consumes this API. (Specified on creation of ThingIFAPI instance.) When you’re sure that the onboard process has been done, this method is convenient. If you are using a gateway, you need to use
ThingIFAPI.onboard(pendingEndnode:endnodePassword:options:completionHandler:)
to onboard endnode instead.Note: You should not call onboard second time, after successfully onboarded. Otherwise, ThingIFError.ALREADY_ONBOARDED will be returned in completionHandler callback.
Declaration
Swift
open func onboardWith( thingID:String, thingPassword:String, options:OnboardWithThingIDOptions? = nil, completionHandler: @escaping (Target?, ThingIFError?)-> Void ) ->Void
Parameters
thingID
Thing ID given by IoT Cloud. Must be specified.
thingPassword
Thing Password given by vendor. Must be specified.
options
Optional parameters inside.
completionHandler
A closure to be executed once onboard has finished. The closure takes 2 arguments: an target, an ThingIFError
-
Onboard IoT Cloud with the specified vendor thing ID. Specified thing will be owned by owner who consumes this API. (Specified on creation of ThingIFAPI instance.)
If you are using a gateway, you need to use
ThingIFAPI.onboard(pendingEndnode:endnodePassword:options:completionHandler:)
to onboard endnode instead.Note: You should not call onboard second time, after successfully onboarded. Otherwise, ThingIFError.ALREADY_ONBOARDED will be returned in completionHandler callback.
Declaration
Swift
open func onboardWith( vendorThingID:String, thingPassword:String, options:OnboardWithVendorThingIDOptions? = nil, completionHandler: @escaping (Target?, ThingIFError?)-> Void ) ->Void
Parameters
vendorThingID
Thing ID given by vendor. Must be specified.
thingPassword
Thing Password given by vendor. Must be specified.
options
Optional parameters inside.
completionHandler
A closure to be executed once onboard has finished. The closure takes 2 arguments: an target, an ThingIFError
-
Endpoints execute onboarding for the thing and merge MQTT channel to the gateway. Thing act as Gateway is already registered and marked as Gateway.
Declaration
Swift
open func onboard( _ pendingEndnode:PendingEndNode, endnodePassword:String, completionHandler: @escaping (EndNode?, ThingIFError?)-> Void ) ->Void
-
Post new Trigger to IoT Cloud.
Note: Please onboard first, or provide a target instance by calling copyWithTarget. Otherwise, KiiCloudError.TARGET_NOT_AVAILABLE will be return in completionHandler callback
When thing related to this ThingIFAPI instance meets condition described by predicate, A registered command sends to thing related to
TriggeredCommandForm.targetID
.target
property andTriggeredCommandForm.targetID
must be same owner’s things.Declaration
Swift
open func postNewTrigger( _ triggeredCommandForm:TriggeredCommandForm, predicate:Predicate, options:TriggerOptions? = nil, completionHandler: @escaping (Trigger?, ThingIFError?) -> Void) -> Void
-
Post new Trigger to IoT Cloud.
Note: Please onboard first, or provide a target instance by calling copyWithTarget. Otherwise, KiiCloudError.TARGET_NOT_AVAILABLE will be return in completionHandler callback
Declaration
Swift
open func postNewTrigger( _ serverCode:ServerCode, predicate:Predicate, options:TriggerOptions? = nil, completionHandler: @escaping (Trigger?, ThingIFError?)-> Void )
-
Apply patch to a registered Trigger Modify a registered Trigger with the specified patch.
Note: Please onboard first, or provide a target instance by calling copyWithTarget. Otherwise, KiiCloudError.TARGET_NOT_AVAILABLE will be return in completionHandler callback
target
property andTriggeredCommandForm.targetID
must be same owner’s things.Declaration
Swift
open func patchTrigger( _ triggerID:String, triggeredCommandForm:TriggeredCommandForm? = nil, predicate:Predicate? = nil, options:TriggerOptions? = nil, completionHandler: @escaping (Trigger?, ThingIFError?) -> Void) -> Void
Parameters
triggerID
ID of the Trigger to which the patch is applied.
triggeredCommandForm
Modified triggered command form to patch trigger.
predicate
Modified Predicate to be applied as patch.
options
Modified optional data for this trigger.
completionHandler
A closure to be executed once finished. The closure takes 2 arguments: 1st one is the modified Trigger instance, 2nd one is an ThingIFError instance when failed.
-
Apply patch to a registered Trigger. Modify a registered Trigger with the specified patch.
Note: Please onboard first, or provide a target instance by calling copyWithTarget. Otherwise, KiiCloudError.TARGET_NOT_AVAILABLE will be return in completionHandler callback
Declaration
Swift
open func patchTrigger( _ triggerID:String, serverCode:ServerCode? = nil, predicate:Predicate? = nil, options:TriggerOptions? = nil, completionHandler: @escaping (Trigger?, ThingIFError?)-> Void )
-
Enable/Disable a registered Trigger
If its already enabled(/disabled), this method won’t throw error and behaveas succeeded.
Note: Please onboard first, or provide a target instance by calling copyWithTarget. Otherwise, KiiCloudError.TARGET_NOT_AVAILABLE will be return in completionHandler callback
Declaration
Swift
open func enableTrigger( _ triggerID: String, enable: Bool, completionHandler: @escaping (Trigger?, ThingIFError?)-> Void) -> Void
-
Delete a registered Trigger.
Note: Please onboard first, or provide a target instance by calling copyWithTarget. Otherwise, KiiCloudError.TARGET_NOT_AVAILABLE will be return in completionHandler callback
Declaration
Swift
open func deleteTrigger( _ triggerID: String, completionHandler: @escaping (String, ThingIFError?)-> Void) -> Void
-
Retrieves list of server code results that was executed by the specified trigger.
Results will be listing with order by modified date descending (latest first)
Note: Please onboard first, or provide a target instance by calling copyWithTarget. Otherwise, KiiCloudError.TARGET_NOT_AVAILABLE will be return in completionHandler callback
Declaration
Swift
open func listTriggeredServerCodeResults( _ triggerID:String, bestEffortLimit:Int? = nil, paginationKey:String? = nil, completionHandler: @escaping ( _ results:[TriggeredServerCodeResult]?, _ paginationKey:String?, _ error: ThingIFError?) -> Void) -> Void
-
List Triggers belongs to the specified Target
Note: Please onboard first, or provide a target instance by calling copyWithTarget. Otherwise, KiiCloudError.TARGET_NOT_AVAILABLE will be return in completionHandler callback
Declaration
Swift
open func listTriggers( _ bestEffortLimit:Int? = nil, paginationKey:String? = nil, completionHandler: @escaping (_ triggers:[Trigger]?, _ paginationKey:String?, _ error: ThingIFError?)-> Void) -> Void
-
Get specified trigger
Note: Please onboard first, or provide a target instance by calling copyWithTarget. Otherwise, KiiCloudError.TARGET_NOT_AVAILABLE will be return in completionHandler callback
Declaration
Swift
open func getTrigger( _ triggerID:String, completionHandler: @escaping (Trigger?, ThingIFError?)-> Void) -> Void
-
Install push notification to receive notification from IoT Cloud. IoT Cloud will send notification when the Target replies to the Command. Application can receive the notification and check the result of Command fired by Application or registered Trigger. After installation is done Installation ID is managed in this class.
Declaration
Swift
open func installPush( _ deviceToken:Data, development:Bool=false, completionHandler: @escaping (String?, ThingIFError?)-> Void )
-
Uninstall push notification. After done, notification from IoT Cloud won’t be notified.
Declaration
Swift
open func uninstallPush( _ installationID: String? = nil, completionHandler: @escaping (ThingIFError?)-> Void )
-
Post new command to IoT Cloud.
Command will be delivered to specified target and result will be notified through push notification.
Note: Please onboard first, or provide a target instance by calling copyWithTarget. Otherwise, KiiCloudError.TARGET_NOT_AVAILABLE will be return in completionHandler callback
Declaration
Swift
open func postNewCommand( _ commandForm: CommandForm, completionHandler: @escaping (Command?, ThingIFError?) -> Void) -> Void
Parameters
commandForm
Command form of posting command.
completionHandler
A closure to be executed once finished. The closure takes 2 arguments: an instance of created command, an instance of ThingIFError when failed.
-
Get specified command
Note: Please onboard first, or provide a target instance by calling copyWithTarget. Otherwise, KiiCloudError.TARGET_NOT_AVAILABLE will be return in completionHandler callback
Declaration
Swift
open func getCommand( _ commandID:String, completionHandler: @escaping (Command?, ThingIFError?)-> Void) -> Void
-
List Commands in the specified Target.
Note: Please onboard first, or provide a target instance by calling copyWithTarget. Otherwise, KiiCloudError.TARGET_NOT_AVAILABLE will be return in completionHandler callback
Declaration
Swift
open func listCommands( _ bestEffortLimit: Int? = nil, paginationKey: String? = nil, completionHandler: @escaping ([Command]?, String?, ThingIFError?)-> Void ) -> Void
Return Value
Where 1st element is Array of the commands belongs to the Target. 2nd element is paginationKey if there is further page to be retrieved.
-
Get the Vendor Thing ID of specified Target.
Declaration
Swift
open func getVendorThingID( _ completionHandler: @escaping (String?, ThingIFError?)-> Void ) -> Void
-
Update the Vendor Thing ID of specified Target.
Declaration
Swift
open func update( vendorThingID: String, password: String, completionHandler: @escaping (ThingIFError?)-> Void )
-
Get firmware version.
This method gets firmware version for
target
thing.Declaration
Swift
open func getFirmwareVersion( _ completionHandler: @escaping (String?, ThingIFError?) -> Void) -> Void
-
Update firmware version.
This method updates firmware version for
target
thing.Declaration
Swift
open func update( firmwareVersion: String, completionHandler: @escaping (ThingIFError?)-> Void) -> Void
-
Get thing type.
This method gets thing type for
target
thing.Declaration
Swift
open func getThingType( _ completionHandler: @escaping (String?, ThingIFError?) -> Void) -> Void
-
Update thing type.
This method updates thing type for
target
thing.Declaration
Swift
open func update( thingType: String, completionHandler: @escaping (ThingIFError?)-> Void) -> Void