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

Widget Intent does not work on macOS Sequoia
Environment Xcode: 16.1 Swift 6 and SwiftUI for macOS development macOS Sequoia I have an app for macOS, and that uses an interactive widget feature. On macOS Sequoia, the widget does not display anything and widget intent doesn't work either. I tested it on macOS Sonoma and it totally works. I assume it's a macOS bug. The app has been working fine before Sequoia. Even on Xcode, when I tried to run the widget preview, Failed to load widget. The operation couldn't be completed. (WidgetKit_Simulator.WidgetDocument.Error error 4.). I could avoid the error by changing version and build numbers, but I still got The operation couldn't be completed. (CHSErrorDomain error 1103.) How am I able to fix the issue? I wanna at least know if its a bug from the app or macOS Sequoia.
0
0
130
3w
AppIntentTimelineProvider "func timeline(for" is called twice after a widget button triggers an AppIntent Perform
I'm adding widget interactivity to my home screen widgets via buttons and AppIntents, but running into some interesting behavior the way the timeline is reloaded after. I'm following this guide from Apple https://developer.apple.com/documentation/widgetkit/adding-interactivity-to-widgets-and-live-activities And the widget is guaranteed to be reloaded when a button pressed with an intent, But whenever the AppIntent is done with the perform action, the widget timeline is always reloaded twice. It's also interesting to note that both reloads happen after the perform method. If you add a 10 second sleep in the perform, nothing happens for 10 seconds, then both reloads happen. This issue with this is 2-fold. calculating and rendering the entire widget timeline can be Networking and DB intensive operations, so I would ideally like to avoid doing all the work twice and save the users battery and processing. The even worse issue, sometimes data on the server changes in between the split second duplicate widget timeline reloads, causing the widget to flash one state, then update to another a second later which is not a good user experience. I have a sample project which shows the issue and is very easy to reproduce. The widget simply keeps track of the number of reloads. To reproduce: Add the widget to the homescreen Press the refresh button, and observe the timeline refresh count always goes up by 2. I've filed a Feedback and attached the sample project and screen recording for anyone to reproduce. FB15595835
1
0
311
2w
Data sharing between WidgetWatchExtension and watchOS/iOS app
When I try to access the data in my IntentTimelineProvider in the recommendations function using App Groups, it is always empty "no data". func recommendations() -> [IntentRecommendation<IndicatorIntent>] { if let sharedUD = UserDefaults(suiteName: "group.measurements") { let jm = JanitzaMeasurementValue(identifier: "1", display: "2") let intent = IndicatorIntent() intent.indicatorWidgetData = jm let desc = sharedUD.string(forKey: "string") ?? "no data" return [IntentRecommendation(intent: intent, description: desc)] } return [] } Although I write this in both the watchOS and iOS app using App Groups. if let sharedUD = UserDefaults(suiteName: "group.measurements") { sharedUD.set("test", forKey: "string") } What is the right way to dynamically implement the widgets for Complications in watchOS? Like for example in Shortcuts App. **Thanks for support **
3
2
232
2w
AppDependcy in Widgets Extension
I am trying to get Controls working using AppIntents. My Intents make use of @Dependency, which get set up during application launch using AppDependencyManager.shared.add { ... }. When the app has been launched, my Controls work fine. However, when the app gets killed using the app switcher or by the system, my Controls cease to work. Checking in Console.app, I found the following: PROGRAMMING ERROR: Failed to retrieve dependency of type {my dependency}. Please register your dependency with AppDependencyManager before performing a dependent intent. My intents use openAppWhenRun = true, so I don't understand why the dependencies are not registered when running the Intent. Alternatively, I would like to know how to register AppDependencies in a Widgets Extension.
0
0
147
3w
Widget is not configurable on iOS 16
I created an Intent-based widget for my iOS app. The deployment target is iOS 16, but I stick to Intent vs AppIntent because I don't like how the configuration list pops up vs the list with search in the old API. So, the configuration works fine on iOS 17/18, but iOS 16 shows the error "unable to load" or just a blank view. This is how it looks on iOS 17/18 I don't see any specific errors in a console or warnings.
2
2
148
2w
EntityQuery defaultResult is not called again when new widgets are added. Shows stale data.
I'm converting my app to use the new AppIntent system in the widgets from the old custom intent based system. I'm trying to implement defaultResult in my EntityQuery, so the widget can be ready to go as soon as it's added to the home screen. https://developer.apple.com/documentation/widgetkit/making-a-configurable-widget https://developer.apple.com/documentation/appintents/uniqueappentityprovider/defaultresult() But the weird behavior is that defaultResult seems to be called once when the first widget is added to a home screen, and shows the correct data, but then the defaultResult method is never called again when subsequent widgets are added. It just uses the result from when the first widget was added. This especially causes issues because then a user will delete the item that the first widget was referencing, but adding new widgets still try to refer to the old AppEntity that no longer exists, even though "entities(for " returns nil for those IDs to signify that item no longer exists. I would have assumed defaultResult would get called every time a new widget is added, but haven't seen anyone else complain about this. Has anyone seen this issue before or have any advice?
3
1
233
3w
TimelineView in LiveActivity Widget called only twice
Hello, I have a live activity widget that displays the passing time during a meeting. It uses a TimelineView to update a custom circular progress bar (that overlaps) and a passing timer. It used to work before Xcode 16, now for some reason the completion handler it's called exactly 2 times and no more, no matter how I set the schedule interval (used to be .animation, but I've tried to update every seconds too). In comparison a Text(timeInterval: ...) view is updated correctly. I've also tried the same code under Xcode 16.1 RC and iOS 18.1 but the results are the same. This behavior happens on the preview, the simulator and actual device. Is there something changed that prevents the use of TimelineViews in widgets on iOS 18?
3
1
118
3w
Critical Bug in iOS 18.1 RC and watchOS 11.1 RC - WidgetKit Complications Not Syncing
I've encountered a major issue with the iOS 18.1 RC and watchOS 11.1 RC. It appears that complications running on WidgetKit cannot be synced as .watchface to these new release candidates. The error message indicates that "the Watch Faces app and complication are not available," which is affecting all apps utilizing WidgetKit. This issue renders all WidgetKit-based complications unusable on watchOS 11.1 RC. It’s a serious problem for those of us who rely on these complications for our apps and for users expecting consistent functionality. APPLE, PLEASE FIX THIS ISSUE ASAP! This bug is a significant setback for developers and users alike, and any guidance or updates would be greatly appreciated.
3
0
327
4w
Sample ActivityConfiguration for Apple Watch?
I'm unable to find sample code that demonstrates how to support a custom Live Activity layout for Apple Watch. I have read the documentation and have added the supplementalActivityFamilies with small and medium. However, I am not able to detect when the activityFamily is set to small. This is what I'm trying to use without success: struct MyWidgetLiveActivity: Widget { @Environment(\.activityFamily) var activityFamily: ActivityFamily var body: some WidgetConfiguration { ActivityConfiguration(for: MyWidgetAttributes.self) { context in if activityFamily == .small { Text("Apple Watch! \(activityFamily.description)") } else { Text("Not small family: \(activityFamily.description)") } } dynamicIsland: { context in return DynamicIsland { DynamicIslandExpandedRegion(.leading) { Text("Leading") } DynamicIslandExpandedRegion(.trailing) { Text("Trailing") } DynamicIslandExpandedRegion(.bottom) { Text("Bottom") } } compactLeading: { Text("CL") } compactTrailing: { Text("CT") } minimal: { Text("M") } } .supplementalActivityFamilies([.small, .medium]) } } This code shows "Not small family: medium" on my Apple Watch. Could somebody provide some insight into why this doesn't work for me?
2
0
159
3w
How to detect interaction of the widget's toggle at locked device
https://developer.apple.com/documentation/WidgetKit/Adding-interactivity-to-widgets-and-Live-Activities#Add-a-toggle Before explaining the situation, I referred to this document. I'm making a widget with a toggle that works with Intent. (To be precise, it's Live Activity, but Apple's literally toggling and button interaction are implemented in the same way) If you press the toggle when the device is locked, the toggle represents the state. However, as described at the top of the same document, the device must be unlocked to execute Intent, so I can't actually change the data. That's fine, but how can I return the isOn of the toggle to false? I'm blocked here because no code is executed. If it is a widget in the home screen, it will be basically unlocked, so I can proceed according to the method of the document, but if it is today's view, user can access it even if device is locked. I tested it in today's view with the Reminders app, If I don't unlock the device after tapping the toggle it returns the toggle back to false state. I wonder how I can achieve this. Is there an API that I missed? Summary. Tap the toggle of the widget while the device is locked. The device waits for unlocking, but the user cancels it without unlocking it. (Still locked) Return the isOn of the toggle to false. <- The part I want.
2
0
178
2w
How to fix TINT mode easily since it is iOS 18
To set up iOS 18 widget tint mode without any modifications, follow the steps below. I hope this helps many people. You just need to add one line. .containerBackgroundRemovable(false) ex) struct create_view: Widget { let kind: String = "CalendarWidget" var body: some WidgetConfiguration { StaticConfiguration(kind: kind, provider: Provider()) { entry in calendar_widgetEntryView(entry: entry) } .supportedFamilies([.systemLarge]) .containerBackgroundRemovable(false) .contentMarginsDisabledIfAvailable() } } Before: After :
0
0
111
Oct ’24
Migrating Widgets from SiriKit Intents to AppIntents Causes widgets to crash with "Unknown extension process"
I'm attempting to migrate my app's Homescreen widget from using the old SiriKit Intent system to the new AppIntent system but running into an issue. This WWDC video is the main source of information I have been going off of. https://developer.apple.com/videos/play/tech-talks/10168/ The problem I'm having is no matter what config I try, as soon as I upgrade to the new app with the AppIntent Widget, all the current widgets on the homescreen stop working, and just show a black screen. Deleting and re-adding the widget to the homescreen from scratch works fine though. I found someone else with a similar issue here on the Apple developer forums, but it didn't look like there was much information or resolution. https://developer.apple.com/forums/thread/759751 https://feedbackassistant.apple.com/feedback/14678285 I used XCode's built in Intent migration UI to create the new CustomIntentMigratedAppIntent which should help migrate the old widgets to the new system. I also double-checked all the names and variable types, and the automatically generated file seems to be correct. I even went ahead and created a brand new empty app with the same app and extension bundle id, and made a hard coded widget which contains the migrated intents, just to make sure nothing in my widget or app code is wrong. And even with the empty app with hardcoded views, the widget is still dead after upgrading the app. It almost seems like the widget is getting disassociated from the app. Even though the app has a new name, the old widget will still show the old name, the widget also does not give any option to edit it, only delete it. And on the new app, I am able to attach my debugger to the widget extension process, but no code inside my timeline, intent, or entity seem to ever be called/run. I looked at the Console log while forcing a refresh of the widget, and I've attached the full logs here, and there is a lot in there about it refreshing widgets. SEE LOGS HERE: Tomer_Logs.txt But one line that stands out, is this error which appears every time the old widget is refreshed [com.shemeshapps.MinecraftServerStatus::com.shemeshapps.MinecraftServerStatus.MinecraftServerStatusHSWidget:MinecraftServerStatusHSWidget:-5734839072461827392] Reload failed; 0 retries remaining: ChronoCoreErrorDomain (1) Error Domain=ChronoCoreErrorDomain Code=1 "Unknown extension process" UserInfo={NSLocalizedDescription=Unknown extension process} Any help in greatly appreciated, Either issues you think might be causing this, or any tips on debugging further! Thanks! I've gone ahead and filled a Feedback, as well as submitted a DTS issue, as this is a release blocker. (The feedback contains the new and old project files to allow anyone to reproduce.) FB15531563 DTS case ID: 9677328
3
1
479
1w
Using a custom DiscreteFormatStyle in Live Activities
With iOS 18, Text has a new initializer that takes in a TimeDataSource and a DiscreteFormatStyle. Similar to this question, I'd like to make a compact timer but can't find a way to do that with any of the system formats. Since the new API takes in a DiscreteFormatStyle though I figure I could make my own. This works in an app but not in a Live Activity; in Previews it crashes and in the simulator the view looks like placeholder. Are custom format styles not supported in this case? Or might there something wrong with my implementation? Formatter Preview Crash Log
1
1
215
Oct ’24
Text(date, style: .timer) issues with watchOS widget
I'm using Text(date, style: .timer) to display a timer in a WatchOS widget, which works great. The problem is that when the watchface goes dim the time goes from showing the time as "MM:SS" to showing "M minutes". Why is this occuring and how can I change the behavior? I understand it needs to remove seconds to preseve battery life, but why it is putting the word "minutes" at the end, this is messing up my layout. Thanks.
1
0
210
Oct ’24
Setting tint for widget snapshot tests iOS 18
We have widget snapshot tests using XCTest as shown below: func testHomeWidgetView() { let widgetView = HomeWidgetView( state: .done, text: "All done!" ).frame(width: 170, height: 170) assertSnapshot(matching: widgetView, as: .image) } } Is it possible to apply a tint to the widgets in snapshot tests like a user can from their home screen in iOS 18? We'd like to capture snapshots of our widget while tinted via the home screen.
1
2
190
3w
iOS 18 Recommended Tweak
Prior to iOS 18 I could interact with my touchscreen when my phone was in standby mode. This was perfect because I could check weather, time, date, pause and play music, change songs, all at my desk, all without picking up my phone from the wireless charger. This feature is now gone in iOS 18 and I would REALLY like it back. It was super useful all day at work and now I’m constantly fumbling with my phone for every little thing.
1
0
260
Oct ’24
LockedCameraCaptureManager
Task { for await update in LockedCameraCaptureManager.shared.sessionContentUpdates { switch update { case .initial(let urls): print("frank: init \(urls)") await MainActor.run { let label = UILabel(frame: CGRect(x: 100, y: 100, width: 100, height: 30)) label.text = "frank test" label.textColor = .black UIViewController.getTop().view.addSubview(label) } case .added(let url): print("frank: add \(url)") case .removed(let url): print("frank: removed \(url)") default: break } } } why 'case .initial(let urls)': never never be executed? Can some one provide a sample code?
1
0
207
Oct ’24
Battery Displays for Custom Hardware
I am having difficulty figuring out two indicators for a custom piece of battery hardware. Firstly, on the home screen, scrolling all the way to the left in the widget screen, you can see the battery for connected wireless devices, electronic pencils, etc. Additionally, when you use Apple battery packs, you can see the battery for it on the top right of your phone I am wondering where I should look to see how I could integrate both of these. I have searched the documentation for a while, and I am having a hard time knowing where to start. If anyone can point me to something, it would be very appreciated. Thank you!
0
0
160
Oct ’24