Last Updated on : 2025-03-10 06:25:28download
App Groups
settings:
App Groups
permission. Ensure that the App Group information is consistent between the WidgetExtension project and the App project.
APP_GROUP_NAME
. Ensure that APP_GROUP_NAME
in the WidgetExtension project matches APP_GROUP_NAME
in the App project. This consistency is necessary for the WidgetExtension to correctly read user information from the App.[ThingSmartSDK sharedInstance].appGroupId = APP_GROUP_NAME;
[[ThingSmartSDK sharedInstance] startWithAppKey:SDK_APPKEY secretKey:SDK_APPSECRET];
homeId
) in the App project.ThingSmartDeviceModel.switchDp
in the WidgetExtension project to determine if the device supports a quick switch.ThingSmartDevice.publishDps
in the WidgetExtension project to modify the device’s DP status.let smartDevice = ThingSmartDevice(deviceId: devId)
if let switchStatus {
// Toggle the switchStatus value
let status = !switchStatus
// Prepare a dictionary to store the DP updates
var dps: [String: Any] = [:]
// Iterate over switchDps and set each data point ID to the toggled status
smartDevice?.deviceModel.switchDps?.forEach({ dpId in
dps[dpId.stringValue] = status
})
// Publish the DP updates using internet mode
smartDevice?.publishDps(dps, mode: ThingDevicePublishModeInternet) {
continuation.resume() // Resume on success
} failure: { error in
continuation.resume() // Resume on failure
}
}
Is this page helpful?
YesFeedbackIs this page helpful?
YesFeedback