- 创建medicineExtension小组件,支持iOS桌面显示用药计划 - 实现App Group数据共享机制,支持主应用与小组件数据同步 - 添加AppGroupUserDefaultsManager原生模块,提供跨应用数据访问能力 - 添加WidgetManager和WidgetCenterHelper,实现小组件刷新控制 - 在medications页面和Redux store中集成小组件数据同步逻辑 - 支持实时同步今日用药状态(待服用/已服用/已错过)到小组件 - 配置App Group entitlements (group.com.anonymous.digitalpilates) - 更新Xcode项目配置,添加WidgetKit和SwiftUI框架支持
78 lines
2.0 KiB
Swift
78 lines
2.0 KiB
Swift
//
|
|
// medicineControl.swift
|
|
// medicine
|
|
//
|
|
// Created by richard on 2025/11/13.
|
|
//
|
|
|
|
import AppIntents
|
|
import SwiftUI
|
|
import WidgetKit
|
|
|
|
struct medicineControl: ControlWidget {
|
|
static let kind: String = "com.anonymous.digitalpilates.medicine"
|
|
|
|
var body: some ControlWidgetConfiguration {
|
|
AppIntentControlConfiguration(
|
|
kind: Self.kind,
|
|
provider: Provider()
|
|
) { value in
|
|
ControlWidgetToggle(
|
|
"Start Timer",
|
|
isOn: value.isRunning,
|
|
action: StartTimerIntent(value.name)
|
|
) { isRunning in
|
|
Label(isRunning ? "On" : "Off", systemImage: "timer")
|
|
}
|
|
}
|
|
.displayName("Timer")
|
|
.description("A an example control that runs a timer.")
|
|
}
|
|
}
|
|
|
|
extension medicineControl {
|
|
struct Value {
|
|
var isRunning: Bool
|
|
var name: String
|
|
}
|
|
|
|
struct Provider: AppIntentControlValueProvider {
|
|
func previewValue(configuration: TimerConfiguration) -> Value {
|
|
medicineControl.Value(isRunning: false, name: configuration.timerName)
|
|
}
|
|
|
|
func currentValue(configuration: TimerConfiguration) async throws -> Value {
|
|
let isRunning = true // Check if the timer is running
|
|
return medicineControl.Value(isRunning: isRunning, name: configuration.timerName)
|
|
}
|
|
}
|
|
}
|
|
|
|
struct TimerConfiguration: ControlConfigurationIntent {
|
|
static let title: LocalizedStringResource = "Timer Name Configuration"
|
|
|
|
@Parameter(title: "Timer Name", default: "Timer")
|
|
var timerName: String
|
|
}
|
|
|
|
struct StartTimerIntent: SetValueIntent {
|
|
static let title: LocalizedStringResource = "Start a timer"
|
|
|
|
@Parameter(title: "Timer Name")
|
|
var name: String
|
|
|
|
@Parameter(title: "Timer is running")
|
|
var value: Bool
|
|
|
|
init() {}
|
|
|
|
init(_ name: String) {
|
|
self.name = name
|
|
}
|
|
|
|
func perform() async throws -> some IntentResult {
|
|
// Start the timer…
|
|
return .result()
|
|
}
|
|
}
|