Set and Get Properties
Once logged in to the application, you can store and retrieve a limited amount of user or device specific information by using Set PropertyEvent and GetPropertyEvent. Aside from having a key and a value which specify the name of the property and the value, our properties have some additional components:
- First, our properties have an owner which defines the owner of the property, i.e. whether is a property of a specific device, a specific user, or a user group.
- Next, they have a specific type, e.g. integer, boolean, string, or others. This type needs to be taken into account when interpreting the bytes representing the value.
- Finally, there are a couple of flags, which specify specific details of the behaviour, most commonly used are the flags for the access and the cache policies.
The flows for setting and getting properties involve the events detailed in the respective tables.
SetProperty event flow-diagram
Here is the event flow diagram to show the details of how this works:
GetProperty event flow-diagram
Here is the event flow diagram to show the details of how this works:
iOS/Swift
For Swift, you can use the following code snippets, where the completion handler handles the response to the event:
public func triggerSetProperty(key: String, data: Data, ownerType: KSMPropertyOwnerType, withCompletionHandler completionBlock: @escaping ((KsEvent?) -> Void)) {
let setProperty = KSMSetPropertyEvent(propertyKey: key, withPropertyData: data, with: .utf8String, with: ownerType, withPropertyTtl: 0, withPropertyFlags: 0)
masterControllerAdapter.sendEvent2MasterController(setProperty, withCompletionHandler: completionBlock)
}
public func triggerGetProperty(key: String, ownerType: KSMPropertyOwnerType,
withCompletionHandler completionBlock: @escaping ((KsEvent?) -> Void)) {
let getProperty = KSMGetPropertyEvent(propertyKey: key, with: ownerType)
masterControllerAdapter.sendEvent2MasterController(getProperty, withCompletionHandler: completionBlock)
}
Android/Kotlin
For Kotlin, we have created dedicated methods in the MCHandler class of our example app to trigger respective events. Below are the code snippets:
fun triggerSetPropertyEvent(propertyKey: String, propertyOwnerType: Property
OwnerType, propertyData: ByteArray, propertyType: PropertyType, ttl: Int, flags:
Int ): Future? {
logDebug(
"triggering Set property event for propertyKey -> $propertyKey && propertyOwnerType -> $propertyOwnerType && propertyData -> ${String(propertyData)} " +
"propertyType -> $propertyType && propertyTtl -> $ttl && propertyFlags -> $flags",
"triggerSetPropertyEvent",
TAG
)
val setPropertyEvent = SetPropertyEvent(propertyKey, propertyData, propertyType, propertyOwnerType, ttl, flags)
return mcEventHandler?.postEvent(setPropertyEvent)
}
fun triggerGetPropertyEvent(propertyKey: String, propertyOwnerType: Property
OwnerType): Future? {
logDebug(
"triggering Get property event for propertyKey => $propertyKey && propertyOwnerType -> $propertyOwnerType",
"triggerGetPropertyEvent",
TAG
)
val getPropertyEvent = GetPropertyEvent(propertyKey, propertyOwnerType);
return mcEventHandler?.postEvent(getPropertyEvent)
}