I wish to write an iOS widget that works like SwichBot and controls the scene. The widget modifications state after being clicked and returns to its unique state. How is that this achieved? Does anybody know?
I’m now utilizing Button to manage AppIntent. When executing carry out()
, I name the community interface to acquire the outcome, reloadAllTimelines()
updates the primary UI to show the corresponding outcome, then waits for two seconds to clear the standing information and reloadAllTimelines()
to replace the second UI.
However what I encounter now could be that the Widget isn’t up to date after reloadAllTimelines()
(it’s OK when related to Xcode for debugging, however it’s not OK when disconnected from Xcode). Because the Widget can not log nicely, it’s unimaginable to examine whether or not the Supplier executes getTimeline()
usually after reloadAllTimelines()
or if there may be any abnormality someplace.
struct ToggleIntent: AppIntent {
static var title: LocalizedStringResource = "Open&Swith Job"
static var description: IntentDescription = IntentDescription("Open and swith system Job")
@Parameter(title: "devicesn")
var deviceSN: String
static var isDiscoverable: Bool = false
init() { }
init(deviceSN: String) {
self.deviceSN = deviceSN
}
typealias DefaultIntentResult = IntentResultContainer
func carry out() async throws -> some IntentResult {
let state = await DataRequest.shared.asyncSmartRequest(id: deviceSN)
WidgetDataManager.replace(state)
WidgetCenter.shared.reloadAllTimelines()
attempt? await Job.sleep(nanoseconds: 2_000_000_000)
WidgetDataManager.restore()
WidgetCenter.shared.reloadAllTimelines()
return DefaultIntentResult.outcome()
}
}
I simply wish to write a widget like SwichBot (carry out an motion, present the standing and restore standing), Is that this a proper means? Does anybody know?