iOS17 widget button intent refresh UI when request callback

29 Views Asked by At

iOS17 for Interactive Widgets, when I click the widget button, then set the button to loading status, and reset the button status to normal after 1s later.

    func perform() async throws -> some IntentResult {

        if let index = TaskDataModel.shared.task.firstIndex(where: {

            $0.id == sceneId

        }) {

            print(" toggle run")

            TaskDataModel.shared.task[index].isCompleted.toggle()

            DispatchQueue.main.asyncAfter(deadline: .now() + 1) {

                TaskDataModel.shared.task[index].isCompleted.toggle()

//                WidgetCenter.shared.reloadTimelines(ofKind: "WidgetExtension")

                WidgetCenter.shared.reloadAllTimelines()

            }

        }

        return .result()

    }

the code is woking fine when debugging, however it failed to work when running in real enviroment. Is there something wrong with my code? And how could I fix the bug ,and implement this function?

0

There are 0 best solutions below