Classically, the demo in the Meet WidgetKit video used a Calendar as an example, where clearly the times to update are simple to calculate based on when the users events will occur.
I'd like to know about the Activity/Fitness Widget. There's no way to tell when a user will burn that next calorie and as far as I can tell, there's still no background observer in HealthKit you can use to call an update on changes. So, with that in mind, how often should I call to update?
This same dilemma applies to ClockKit and WatchOS complications.
Post
Replies
Boosts
Views
Activity
I'm trying to get the individual voltage measurements of an ECG back from Apple HealthKit using new APIs in iOS 14.
I've already managed to use:
let ecgQuery = HKSampleQuery(sampleType: HKObjectType.electrocardiogramType(), predicate: samplePredicate, limit: 0, sortDescriptors: [sortDescriptor]){ (query, results, error) in
which gets me a HKElectrocardiogram object. From this I can see the average heart rate, ECG classification etc...
I now believe I need to pass that object into an HKElectrocardiogramQuery like this:let ecgSample = HKElectrocardiogramQuery(ecg) { (query, result) in
but I can't find any way to extract data from the result data handler. If I put a print in on result, it executes many times but again, I can't extract the data. result is of type HKElectrocardiogramQuery.Result
The documentations pretty sketchy on Apple's developer site with zero examples provided. Any help would be very appreciated.
Cheers
I'm unable to achieve anything like the font size used in the stock templates when trying to create a Circular Gauge in Swift UI. Here is my code for simply displaying three labels. The maximum value label ("101") clips. I can't set a minimumFontScaleFactor on the Text because it's not a proper view. Here is my current code:
struct GaugeSample: View {
var body: some View {
Gauge(value: currentHR, in: minHR...maxHR) {
Image(systemName: "heart.fill")
} currentValueLabel: {
Text("66").complicationForeground()
} minimumValueLabel: {
Text("59")
} maximumValueLabel: {
Text("101")
}
.gaugeStyle(CircularGaugeStyle(tint: Gradient(colors: getGradientColors())))
}
If I just use a previous style complication like this I get the full size text fonts:
let template = CLKComplicationTemplateGraphicCircularOpenGaugeRangeText()
template.centerTextProvider = CLKSimpleTextProvider(text: "99")
template.leadingTextProvider = CLKSimpleTextProvider(text: "40")
template.trailingTextProvider = CLKSimpleTextProvider(text: "120")
template.gaugeProvider = CLKSimpleGaugeProvider(style: .ring, gaugeColors: [UIColor.blue,UIColor.red], gaugeColorLocations: [0.3,0.9], fillFraction: 0.4)
But I want to use the new SwiftUI complications so I can better customize for things like the rendering mode. Any suggestions?
https://developer.apple.com/design/resources/
When I access the above link and scroll down to Add Apple Watch Face and select download, I get redirected to an odd AppleConnect page with some reference to box.com
Other resources seem to work fine, am I doing something wrong? I've tried this on Safari and Chrome and signed into and out of my Apple Developer Account
I'm trying to set the list row background color in my WatchOS app. I support WatchOS 6.2 & 7. The app is fully SwiftUI.
I currently use listRowPlatterColor. I note that this has been deprecated in WatchOS 7 (although it does still work). My issue is with WatchOS 6.2 building from Xcode 12 Beta 6.
Everything I run on a simulator or device with WatchOS 6.2 I get a crash:
EXCBADACCESS
If I remove any instances of listRowPlatterColor, the crash doesn't occur. Why does something that's been deprecated in WatchOS 7 still work there, but not in WatchOS 6?
// Example code crashes on WatchOS 6.2 but not 7
// When building and running from Xcode 12 beta 6
struct TestView: View {
var body: some View {
List {
Text("Hellow World)"
.listRowPlatterColor(.clear)
}
}
}
I've been unable to generate a complication bundle for my iOS and Apple Watch app with the latest Xcode 12 Beta 6 version. I consistently get the error in the title with the following:
2020-09-15 16:58:51.203 clockkitutil[3685:143736] generating gallery complication bundle for (null) at /Users/simon/Documents/gallery.ckcomplication
I've tried this on my own project and I've also downloaded the Apple Sample Coffee Tracker WatchKit app which also exhibits the same problems.
Any help or suggestions? Is this a bug?
I've implemented the steps in the WWDC 2020 Video "Meet Watch Face Sharing" and have managed to add into my app the ability to press a button to add a watch face. This then launches the Apple Watch app showing my complications, but when I then press add, it says Complication not available on your Apple Watch.
I have a Series 5 paired so all faces should be available, I've even implemented a fallback face but that hasn't helped.
In the end all it does is add a blank face to the watch.
Any suggestions?
I'd like to override the style of the widget so that my user's preference of dark mode in the app can also apply in the widget.
In the main SwiftUI app I can use:
SceneDelegate.shared?.window!.overrideUserInterfaceStyle = .dark
But I'm not sure how to use that within the Widget extension. Yes I could define alternative for every single color and piece of text, but even things like the widget system background change with light/dark mode all of which I've have to try to check for and adjust.
If I can override the user interface style, my widget would adjust automatically.
I’m having an issue with an app I’ve developed where it grinds to a halt and freezes when using the TabView with a certain iOS Setting enabled.
To simplify things, I can easily reproduce this with a demo project.
Launch Xcode 12.5, start a new iOS project with swift, swiftUI lifecycle and SwiftUI interface. Then replace the Text code in the content view body with ithe following simple code:
TabView {
Text("Hello, world! Tab 1")
.tabItem {
Label("Tab 1", systemImage: "list.dash")
}
Text("Tab 2")
.tabItem {
Label("Tab 2", systemImage: "list.dash")
}
}
If you launch and run this on device or on the simulator, it all works fine. You can click between the tabs etc…
However, if you navigate to the iPhone settings (and this is available in the simulator) and go Accessibility -> Keyboards -> Full Keyboard Access and toggle this ON, it causes a problem.
When re-opening the app we just made, as soon as you select a tab at the bottom, the app CPU usage jumps to 100%+ and grinds to a halt. The only fix is to force quite the app, but the issue persists on re-launches until you disable Full Keyboard Access.
Is this a bug? Or am I missing something? It seems to have been around throughout iOS 14’s life time.
Thank you
I supported the Always-On display in my app complications from day one but since am continuing to find animation glitches and bugs that have never been fixed and exist currently on WatchOS 8 & 9 (I've tried Series 6 & 8 devices). I'm thinking about scrapping it and just returning the handler(nil).
Does anyone have an example of where they use it and it really adds value to their app complications? And do they have any suggestions to try and work around the glitches?
Thanks
I'm trying to create a UI layout and navigation functionality similar to the Apple Fitness app on Apple Watch.
This is all WatchOS 9 so no need for older API support, phew!
I want to have NavigationTitle set for each view in a TabBar.
I want each selected NavigationDestination to hide the TabBar controls and disable swiping when opened.
I want the NavigationTitle and update to remain whilst navigating between Tabs and Childs.
I've created this sample code based off the Building a productivity app for Apple Watch sample code from Apple and other examples on navigation with the new NavigationStack in WatchOS 9, iOS 16 etc...
import SwiftUI
@main
struct Test_Watch_App_Watch_AppApp: App {
@SceneBuilder var body: some Scene {
WindowGroup {
TabView {
NavigationStack {
ScrollView {
VStack {
NavigationLink("Mint", value: Color.mint)
NavigationLink("Pink", value: Color.pink)
NavigationLink("Teal", value: Color.teal)
}
}
.navigationDestination(for: Color.self) { color in
Text("Hello").background(color)
}
.navigationTitle("Colors")
}
NavigationStack {
ScrollView {
VStack {
NavigationLink("headline", value: Font.headline)
NavigationLink("title", value: Font.title)
NavigationLink("caption", value: Font.caption)
}
}
.navigationDestination(for: Font.self) { font in
Text("Hello").font(font)
}
.navigationTitle("Fonts")
}
}.tabViewStyle(.page)
}
}
}
The problem here is, when selecting any of the Navigation Links, the child view still displays the Tab Bar page indicators and allows you to swipe between the tabs, I don't want this. The functionality as I'd like exists int eh Apple Fitness app on the Watch. The app launches in the Activity Tab. You can swipe across to Sharing, select a person, and in that view it's not then possible to swipe straight back to Activity.
I've tried Embedding the whole TabView in a NavigationStack and removing the NavigationStacks per tab. This works as far as fixing the child views hiding the TabBar page indicator controls and swiping. However, it then breaks NavigationTitles on launch and when moving in and out of Childs, so I don't think it should be this way.
Any help very appreciated.
On my Watch app pre-WatchOS 9 I had code as follows:
`
TabView {
NavigationView {
TodayView(model: delegate.model)
.navigationBarTitleDisplayMode(.large)
}
NavigationView {
SettingsView(model: delegate.model)
}
}
.tabViewStyle(.page)
However, for WatchOS 9 I'm using the new NavigationStack like this:
`
NavigationStack {
TabView {
TodayView(model: delegate.model)
.navigationBarTitleDisplayMode(.large)
The issue is, with WatchOS 9 the title always displays as .inline and never large. I've tried embedding a list or scroll view. I've also tried placing a navigationView within the NavigationStack and TabView, that just makes duplicate titles.
So, using the NavigationStack with a TabView on WatchOS 9, how do you get large titles?
Thanks
For Apple Watch complications displayed on tinted faced, developers can use:
@Environment(\.complicationRenderingMode) var renderingMode
to see if the watch face is tinted. You can then use the
.complicationForeground()
modifier to set elements of the complication to match that tint color. (I appreciate that
.complicationForeground()
is now deprecated in favour of
.widgetAccentable()
but I believe the behaviour is the same).
However, this can only be applied to a view I believe. I'd like to display a Swift Chart where only certain elements of the chart have the
.complicationForeground()
rather than the whole chart.
For example, in one case I'd like the LineMark to pop with the tinted color of the complication whilst the rest of the complication get the gray default tint.
Is there a way to do with with the current APIs?
Thanks
I'm trying to ensure my watch app launches as quickly as possible. I'm using the @WKApplicationDelegateAdaptor because of needing to implement the BackgroundRefresh handlers.
What I'm finding is that the time between the app calling the main init() and then the ExtensionDelegate calling applicationDidFinishLaunching is often > 2 seconds.
I've tried using Instruments to profile the App launch but have never had any luck with the tool on a watch app.
So I then created a blank project just with the elements needed to implement the same WKApplicationDelegateAdaptor and oslog calls, performance was the same... This is tested on WatchOS 9.5 & 9.5. This is on a Series 6 and Series 8 Apple Watch (FYI S6 == S7 == S8 for Apple Watch CPU performance)
Interestingly, on the simulator, the time gap was less, more like 1 second between main init() and applicationDidFinishLaunching.... not sure why this would be this way.
Anyway, for real world device usage, is this the best performance I can expect? Is there anything that can be done to improve this?
Relative Date labels on WatchOS complications do not update when in the .WidgetLabel section modifier. Am I missing anything?
For example if I want a .accessoryCircular complication in the top centre middle of the Infograph Watch Face, I can have maybe an Icon for the app in the circular slot and then use the .WidgetLabel modifier to display text. However, the Text(Date(), style: .relative) will not update in the WidgetLabel area, but it will update in main area. This is a bug I suspect. This same problem also exists with the .accessory corner complications and the WidgetLabel.
The best example of where this works fine currently in the WatchOS system is the Heart Rate complication. Here the WidgetLabel text shows the relative date. It also has formatting options for the date (like only showing minutes), none of this is available to third party developers.
Have tested this on the latest public releases of iOS, WatchOS & Xcode as well as the new iOS 17, WatchOS 10 and Xcode 15 Beta releases.
Example Code:
import SwiftUI
import WidgetKit
struct WatchWidget: Widget {
let kind: String = "WatchWidget"
var body: some WidgetConfiguration {
StaticConfiguration(kind: kind, provider: TimelineProvider()) { entry in
Text(Date(), style: .relative)
.widgetLabel { Text(Date(), style: .relative) }
}
.configurationDisplayName("WatchWidget")
.description("WatchWidget")
.supportedFamilies([.accessoryCircular, .accessoryCorner])
}
}