WidgetKit

RSS for tag

Show relevant, glanceable content from your app on iOS and iPadOS Home Screen and Lock Screen, macOS Desktop, Apple Watch Smart Stack and Complications, and in StandBy mode on iPhone.

Posts under WidgetKit tag

200 Posts
Sort by:

Post

Replies

Boosts

Views

Activity

Getting inconsistent padding on widgets between devices and simulators
I'm trying to design a homescreen widget but I am unable to properly control the padding and sizing of various components. In the four attached screenshots you can see the huge variation in padding around the outside, the change in text colour and the spacing between the text. I've boiled it down as simple as possible and attached the view as a sample file. What I'd like to achieve is a consistent look between iPads and iPhones and ideally in the simulator too. Is there a simple way to set the padding so that all places use the same, and then scale the text so that I know that if the text fits in the simulator the same text will fit on all devices? Device iPad 8 - 17.7 iPhone 13 Pro Max - 17.7 Xcode Canvas - iPad 13" Simulator - iPad Pro sampleview.txt 13"
0
0
284
Sep ’24
**Title:** Lock Screen Widget Settings Not Updating Properly in iOS 18
It seems that after adding a lock screen widget in iOS 18, changing the widget settings doesn't work properly. The first setting change is applied, but after that, adjusting the settings has no effect. This issue appears to be present in other apps like Gmail as well, which suggests it might be an iOS 18 bug. Is there a solution to this problem?
1
0
339
Sep ’24
Springboard crash when trying to add Control Widget
Xcode 16, iOS 18 official release. On both my phone and simulator, when I build the release build of my app, when I go to control center and select "Add a Control", springboard crashes (see attached crash log). Somehow this does not happen in debug config, with debug config (which does have a different bundle ID but everything else is the same) I'm able to add the control widget just fine. The widget code is taken directly from the Apple docs: struct WidgetTestWidgetControl: ControlWidget { static let kind: String = "com.myapp.WidgetTestWidget" 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 WidgetTestWidgetControl { struct Value { var isRunning: Bool var name: String } struct Provider: AppIntentControlValueProvider { func previewValue(configuration: TimerConfiguration) -> Value { WidgetTestWidgetControl.Value(isRunning: false, name: configuration.timerName) } func currentValue(configuration: TimerConfiguration) async throws -> Value { let isRunning = true // Check if the timer is running return WidgetTestWidgetControl.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() } } However in a fresh project I am able to add this widget code and it works completely fine in both debug and release. How can I fix this? This is clearly affecting many apps and is the 'fault' of the app, see these threads: https://www.reddit.com/r/ios/comments/1fiqrd7/ios_18_control_center_keeps_crashing_when_trying/ https://discussions.apple.com/thread/255759997?sortBy=rank crash-log.txt
3
1
1k
Sep ’24
Custom SF Symbols don't work on WatchOS 10 .accessoryInline
I'm trying to use a custom SVG as a SF Symbol for a .accessoryInline complication on Apple Watch but it only appear on WatchOS 11. I even tried a fresh project and exported one of the symbols from SF Symbols app to eliminate error with custom symbol creation. On WatchOS 11 it shows correctly and colored, on WatchOS 10.5, no symbol at all. Am I missing some setting or something? Tried different Render As options for the symbol with no luck. For corner complication, it shows it fine (Series 10 is WatchOS 11 here) What is more weird in kinda shows that it's loading in comlication preview: Overall can't use any image for inline complication unless I do it like this: Image(uiImage: UIImage(named: "ImageName") ?? UIImage()) .resizable() Which can't be colored also
1
0
634
Sep ’24
Black text on white button on iOS 18 Accented Home Screen Widget
Hi. I am making my widgets ready for iOS 18 accented Home Screen widgets. I am having issues setting the color of text to black. This is required as I have a white button with black text and black icon. I have tried manually, without using my Color, to set the text to .black or .white. It will always be white. When applying the accent, I can use the .widgetAccentedRenderingMode(.fullColor) to turn the icon black, but I cannot do this for the text. Button(intent: --intent--) { HStack(alignment: .center) { Text("Play") .font(.system(size: 12, weight: .bold)) .foregroundStyle(Color("buttonAccentColor")) // Problem here, this is forced to be white, I want it to be black Image("resume") .renderingMode(.template) .resizable() .widgetAccentedRenderingMode(.fullColor) // This works .aspectRatio(contentMode: .fit) .frame(width: 16, height: 16) .foregroundStyle(Color("buttonAccentColor")) } .padding(8) .padding(.horizontal, 8) } .buttonStyle(.plain) .background(Color("neutral100")) .clipShape(Capsule())
1
3
481
Oct ’24
What is ChronoKit.InteractiveWidgetActionRunner.Errors Code 1?
This is a follow up to this post about building a Control Center widget to open the app directly to a particular feature. I have it working in a sample app, but when I do the same thing in my full app I get this error: [[com.olivetree.BR-Free::com.olivetree.BR-Free.VerseWidget:com.olivetree.BR-Free.ContinueReadingPlanControl:-]] Control action: failed with error: Error Domain=ChronoKit.InteractiveWidgetActionRunner.Errors Code=1 "(null)" Google has nothing for any of that. Can anyone shed light on what it means? This is my control and its action: @available(iOS 18.0, *) struct ContinueReadingPlanControl : ControlWidget { var body: some ControlWidgetConfiguration { StaticControlConfiguration(kind: "com.olivetree.BR-Free.ContinueReadingPlanControl") { ControlWidgetButton(action: ContinueReadingPlanIntent()) { Image(systemName: "book") } } .displayName("Continue Reading Plan") } } @available(iOS 18.0, *) struct ContinueReadingPlanIntent : ControlConfigurationIntent { static let title: LocalizedStringResource = "Continue Reading Plan" static let description = IntentDescription(stringLiteral: "Continue the last-used reading plan") static let isDiscoverable = false static let opensAppWhenRun: Bool = true @MainActor func perform() async throws -> some IntentResult & OpensIntent { let strUrl = "olivetree://startplanday" UserDefaults.standard.setValue(strUrl, forKey: "StartupUrl") return .result(opensIntent: OpenURLIntent(URL(string: strUrl)!)) } } Note also that I'm pulling this from Console.app, streaming the logs from my device. I don't know of a way to debug a Control Center widget in Xcode, though this thread implies that it's possible.
2
0
679
Sep ’24
Widget link broken by `.desaturated` image rendering mode
Using desaturated mode on an image in a widget will break any links or buttons that use the image as their 'label'. Using the following will just open the app as if there was no link at all - therefore just using the fallback userActivity handler, or any .widgetURL() urls provided. Link(destination: URL(string: "bug://never-works")!) { Image("puppy") .widgetAccentedRenderingMode(.desaturated) } The same goes for buttons: Button(intent: MyDemoIntent()) { Image("puppy") .widgetAccentedRenderingMode(.desaturated) } I've tried hacky solutions like putting the link behind the image using a ZStack, and disabling hit testing on the image, but they don't work. Anything else to try? Logged as Feedback #15152620.
5
2
611
Dec ’24
Text with relative date - sizing bug when used in widget
When using a SwiftUI Text view with a relative date, with .minimumScaleFactor(), in a widget, the Text will always be shown at the minimum scale rather than the largest size possible. This started happening in iOS17, and is still the case in iOS18. Therefore, if for example, you wanted to have a Text, showing a relative date in a countdown, with a "minimumScaleFactor" of 0.5, it will always show at 0.5 scale, no matter how much space there is available. Text(.now, style: .relative) .font(.system(size: 80, weight: .bold, design: .rounded)) .minimumScaleFactor(0.2) ^^ will always show at 0.2 scale (in a widget) even if there's space for much more. This is only the case in widgets, not in the main app. Similarly, if you try to use "ViewThatFits" instead of "minimumScaleFactor", it will choose the smallest view, even if larger ones would fit. Screenshot demonstrates the issue - all the countdown text views should be similarly large. This is not an issue with lack of vertical spacing causing the more flexible views to shrink - it behaves the same even if there's loads of vertical space too. Maybe related, but trying to use ".fixedSize()" with a relative date Text view in a widget results in a completely blank widget. Seems like a system bug rather than anything wrong in my code - I've logged it as Feedback (#15151577) with a demo project. Has anybody else come up against these issues - any solutions?
4
0
533
Sep ’24
ControlWidgetToggle state when parent app is terminated
I have programmed a ControlWidgetToggle which controls a recording state in our main app, that can be on (recording) or off (not recording). The recording can also be controlled from inside the main app, and there we call ControlCenter.shared.reloadControls(ofKind: "") to update the ControlWidgetToggle state when the recording state changes. Now this all works great, except for the situation in which the user terminates the app (for example using the app switcher screen). Then of course the recording will stop. I however have no idea how to update the state of the ControlWidgetToggle in this case, it will stay in the recording state since it does not know that the recording has been stopped. The applicationWillTerminate delegate method of the AppDelegate will not be called in such a case. Does someone has an idea how to update the state of the ControlWidgetToggle once the parent app has been terminated?
1
0
416
Sep ’24
AppIntent - Widget & ControlWidget
Hey all, iOS 18 - RC I have an app that supports both Widgets and ControlWidget, which resides on the same AppIntent. The following sync works fine when any action is taken on any of the three players - App - Widget - both directions - works as expected App - Control Widget - both directions - works as expected However - Widget - ControlWidget - the UI not always sync in real time (the values are ok) So if for instance I increase a counter on the widget from 1 to 2, the comtrolwidget will still show 1, but if I tap it, it will increase to 3. For any update/action taken on the AppInten, I call - WidgetCenter.shared.reloadAllTimelines() ControlCenter.shared.reloadAllControls() Any idea how to ensure this sync? Thanks a lot! Dudi
2
0
632
Sep ’24
Open specific screen in App Delegate after iOS 18 Control Center widget is tapped (failed to open URL)
I have created an iOS 18 Control Center Widget that launches my app. However I am not able to detect it in AppDelegate.swift. I have created custom scheme funRun://beginRun in Target => Info => URL Types URL Types setup in Xcode This method in AppDelegate.swift does not fire at all and I get this error in console: Failed to open URL runFun://beginRun: Error Domain=NSOSStatusErrorDomain Code=-10814 "(null)" UserInfo={_LSLine=279, _LSFunction=-[_LSDOpenClient openURL:fileHandle:options:completionHandler:]}`` ` func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool { // this does not fire print("Scheme \(url.scheme)") print("Host \(url.host)") return true }` I tried this answer to no avail: iOS 18 Control Widget that opens a URL Even adding EnvironmentValues().openURL(url) as suggested here did not help. @MainActor func perform() async throws -> some IntentResult & OpensIntent { let url = URL(string: "funRun://beginRun")! EnvironmentValues().openURL(url) return .result(opensIntent: OpenURLIntent(url)) } Here is my extension code: My goal is to detect the url string from the request, so I can decide which screen to launch from AppDelegate's open url method. When I test this with iOS 18 RC it does not work either in simulator or on real device import AppIntents import SwiftUI import WidgetKit @available(iOS 18.0, watchOS 11.0, macOS 15.0, visionOS 2.0, *) struct StartRunControl: ControlWidget { var body: some ControlWidgetConfiguration { StaticControlConfiguration( kind: "name.funRun.StartRun", provider: Provider() ) { value in ControlWidgetButton("Hello", action: MyIntent()) { hi in Label("Start", systemImage: "sun.min.fill") } } .displayName("Start run") .description("Opens a run screen.") } } @available(iOS 18.0, watchOS 11.0, macOS 15.0, visionOS 2.0, *) extension StartRunControl { struct Provider: ControlValueProvider { var previewValue: Bool { false } func currentValue() async throws -> Bool { let isRunning = true // Check if the timer is running return isRunning } } } @available(iOS 18.0, watchOS 11.0, macOS 15.0, visionOS 2.0, *) struct MyIntent: AppIntent { static let title: LocalizedStringResource = "My Intent" static var openAppWhenRun: Bool = true init() {} @MainActor func perform() async throws -> some IntentResult & OpensIntent { let url = URL(string: "funRun://beginRun")! EnvironmentValues().openURL(url) return .result(opensIntent: OpenURLIntent(url)) } } I even checked info.plist and it seems okay. <key>CFBundleURLTypes</key> <array> <dict> <key>CFBundleTypeRole</key> <string>Editor</string> <key>CFBundleURLName</key> <string>beginRun</string> <key>CFBundleURLSchemes</key> <array> <string>funRun://beginRun</string> </array> </dict> </array> Does anyone know where the problem might be? Thanks!
1
0
1.2k
Sep ’24
Xcode 16 beta 6 - Widget gallery doesn't show app in iOS 15
We have minimum deployments set to iOS 15 in one of the app for both application and widget target. When install app in simulator or real device using Xcode 15.4, it works fine in iOS15, iOS16, iOS17 and iOS18 beta. When install app in simulator or real device, using Xcode 16 beta 6, it works fine in iOS16, iOS17 and iOS18 beta but in iOS 15, our app doesn't show in widget gallery.
18
12
4.5k
Jan ’25
Restricting available units for a Measurement<UnitDuration> @Parameter
Hello, I'm preparing my app Tameno for iOS 18, adding a couple of Control Center widgets. One of them allows users to select their favorite interval. But in the context of my app, only seconds and minutes make sense as a unit value - I don't need milli-pseconds, nor hours. Is there a way restrict these available options that come from a ControlConfigurationIntent? @available(iOS 18.0, iOSApplicationExtension 18.0, *) struct TamenoFavoriteIntervalControlWidgetSetupIntent : ControlConfigurationIntent { static let title: LocalizedStringResource = "cw_FavoriteIntervalSetup" static let isDiscoverable: Bool = false @Parameter(title: "cw_IntervalParameter", defaultValue: 5.0, defaultUnit: .seconds, supportsNegativeNumbers: false) var interval: Measurement<UnitDuration>? @MainActor func perform() async throws -> some IntentResult { .result() } } I am able to restrict it just to seconds or minutes only (by adding unit: .seconds, or unit: .minutes to the @Parameter setup), but I'd really like to offer both. Thank you, Matthias
3
0
546
Sep ’24
How to create a custom TimeDataSource?
Hello. I am working with the iOS 18b8 and Xcode 16b6 betas, updating a Live Activity Widget to adopt the new FormatStyle variants of the SwiftUI Text views. We used to use: Text(workoutStartDate, style: .relative) and it seems with iOS 18 we can replace it with: Text(workoutStartDate, format: .relative(presentation: .numeric, unitsStyle: .wide)) The former code would auto-increment, allowing a user to look at their Live Activity and see the duration of their workout so far ticking by. The new code does provide a nice relative duration string, but it doesn't auto-increment in the Live Activity's View – I need that functionality. I also updated other Texts in the Live Activity's View to adopt the .timer and .stopwatch FormatStyles. Those auto-increment and update no problem – once I realized I needed to provide a TimeDataSource<Date>.currentDate and not a simple Date. But in this .relative case, there is no auto-incrementing, and I'm guessing it may be due to providing a Date (workoutStartDate) and not a TimeDataSource<Date> as TimeDataSource seems to be the magic to make the Text auto-increment (or it's possible this format simply doesn't support auto-increment? bummer if so since the prior way did). How can I have a TimeDataSource<Date> that vends my arbitrary date (workoutStartDate)? I dug around, didn't find anything, but I wouldn't be surprised if I was overlooking something. PS: I have tried other approaches to solve this, such as simply using a .timer or .stopwatch format. That would change the under experience under iOS 18, and we think degrade it (the relative textual representation is nicer and provides distinction from the .timer also in the same View). We could keep the former approach, despite the minor layout issues under iOS 18. I have considered additional approaches as well – and am totally open to more! Here tho, I am truly curious how one might provide a custom TimeDataSource anchored at a date we provide (perhaps dynamically). Thank you.
1
1
645
Oct ’24
Updating control widget with push notification data
I have been trying to add a control widget to my app. Now I want to show some info on control widget that is received from push notification data. In the apple documentation, they have added a push notification handler, but the pushTokensDidChange method only has the information of the controls whose push tokens are changed. There is no information on where can I access the push notification data and how to use the push notification data to update the info being shown in the control widget.
1
0
621
Sep ’24