Event Listeners
Implement all four methods of GizSdkEventHandlerDelegate. Set the delegate before initialization to receive events emitted during SDK setup.
import GizwitsiOSSDK
final class SDKModel: GizSdkEventHandlerDelegate {
func start(config: GizConfigStruct) {
GizSDKManager.sharedInstance.setDelegate(delegate: self)
GizSDKManager.sharedInstance.initSDK(config: config)
}
func onDeviceListUpdate(devices: [GizDevice]) {
// Update the device list.
}
func onDeviceData(device: GizDevice, result: GizJSON, type: GizCapability) {
// Handle device data.
}
func onDeviceState(device: GizDevice, state: GizWifiDeviceNetStatus,
isLogin: Bool, type: GizCapability) {
// Handle connectivity and authentication state.
}
func onDeviceBindState(did: String, isBind: Bool) {
// Handle cloud binding changes.
}
}You can also call await GizSDKManager.sharedInstance.getDevices() to retrieve [GizDevice]; it does not return GizResult. Dispatch UI updates to the main thread.