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
934
Oct ’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
819
Jun ’22
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.
Replies
4
Boosts
0
Views
934
Activity
Oct ’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?
Replies
0
Boosts
0
Views
819
Activity
Jun ’22