Post

Replies

Boosts

Views

Activity

Complication Widget using AccessoryWidgetGroup
I want to get which button in AccessoryWidgetGroup was pressed in the Watch App, but I can't. When I use Button(_:intent:), it works in Smart Stack, but it doesn't work in Complication Widget. Using widgetURL(_:) always gets the URL of the first button. Below is a snippet of the code I tried. All codes can be found here. struct MyWatchWidgetEntryView : View { var entry: Provider.Entry var body: some View { AccessoryWidgetGroup("Widget Group") { MyWatchWidgetEntryButton(intent: .init(id: "001", imageName: "star.fill")) MyWatchWidgetEntryButton(intent: .init(id: "002", imageName: "heart.fill")) MyWatchWidgetEntryButton(intent: .init(id: "003", imageName: "leaf.fill")) } } } //Button View private struct MyWatchWidgetEntryButton: View { @Environment(\.showsWidgetContainerBackground) var showsWidgetContainerBackground let intent: MyAppIntent var body: some View { Button(intent: intent) { ZStack { if showsWidgetContainerBackground { Color.black } else { AccessoryWidgetBackground() } VStack { Image(systemName: intent.imageName) .font(.headline) Text(intent.id) .font(.system(size: 10, weight: .bold)) } } } .buttonStyle(.plain) .widgetURL(URL(string: "widget://" + intent.id)) } } Does anyone know how to do this? Thank you.
4
0
443
Sep ’24
Sort workouts using the HKSampleQueryDescriptor
Is it possible to set TotalDistance for the sorts of HKSampleQueryDescriptor? In HKSampleQuery, I can set TotalDistance as follows. let sort = NSSortDescriptor(key: HKWorkoutSortIdentifierTotalDistance, ascending: false) let type = HKWorkoutType.workoutType() let query = HKSampleQuery(sampleType: type, predicate: nil, limit: 0, sortDescriptors: [sort] ){ (query, results, error) -> Void in } I want to create a SortDescriptor for HKSampleQueryDescriptor. When I set HKWorkout.totalDistance to parameter in SortDescriptor, the compile error occurred. let sort = SortDescriptor(\HKWorkout.totalDistance, order: .forward) // Error: "No exact matches in call to initializer" I know that HKWorkout.totalDistance is deprecated. Isn't it recommended to set TotalDistance to sort? I'm expecting that on iOS 16, I can get my workouts in heart rate order, is this a mistake?
0
0
701
Jun ’22
HKObserverQuery is not immediately call when using Apple Watch?
I created a HKObserverQuery for HKQuantityTypeIdentifierStepCount.If I add the count of steps walked wearing the Apple Watch, UpdateHandler of HKObserverQuery is not trigger immediately.While the app to the active state, UpdateHandler of HKObserverQuery is only called about 2 times per hour.Its timing is regularly. It seems the next call is just called after 30 minutes even if there is new data in the meantime.Strange things are ...When I changed my app to background state and to reactive, updateHandler of HKObserverQuery be called at its timing.In the case of a number of steps that have been registered in the iPhone is called updateHandler immediately.This issue occurs by the data of AppleWatch only.I tried to use timer instead of HKObserverQuery, but did not get the new changed data.Can I get latest data immediately without app to background?or is this bug?Please advise!
5
0
2.3k
Feb ’16