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

Can I increase the reliability of my app intent updating my widgets?
We have widgets in our app. We're now working on a Live Activitiy with a button calling an app intent. This app intent needs to update our Widgets, and we're seeing semi-great results. When we're updating the widgets from within the app, it works great. Also from geofence triggers it usually works, so we're thinking it might have to do with the "widget update budget"? According to the docs: Cases in which WidgetKit doesn’t count reloads against your widget’s budget include when: The widget performs an app intent, such as when the user taps a button or toggles a switch. But we're not really seeing that. When I run our app from within Xcode, everything runs great all the time and the widget gets updated within milliseconds, but when running the TestFlight version is more spotty. To be clear: This is a button in a live activity, calling an app intent, and in turn, the app intent is calling reloadAllTimelines for our "regular" widgets. The live activity itself always gets updated properly. My question is basically, am I doing something wrong and can I do something to increase the consistency of the widget updating on time? Abbreviated example: final class UserEventIntent: NSObject, LiveActivityIntent { @MainActor func perform() async throws -> some IntentResult { do { let newStatus: (stat: Status, wasSame: Bool) = try await eventHelper.performEvent(status: status) WidgetCenter.shared.reloadAllTimelines() }catch { await WidgetCenterBridge.updateLiveActivityForInProgress(false) } return .result() }
2
0
199
Oct ’24
How can I use an image for my live activity smartstack layout?
Hello, I am updating my live activity for the new ios18 Smart Stack functionality. I got it working through the WWDC session (Bring your live activities to Apple watch). I'm doing supplementalActivityFamilies([.small]) and then a custom layout in the .small ActivityFamily However, any images I try to use in the Smart Stack just show up as grey squares. (it works on the phone live activity) I suspect it's because my app images are not moved over to the watch? Because I don't have a watch app and such no watch target? If anyone can help me understand if there's anything I can do in order to have a custom image show up on the smart stack, I'd be very grateful.
3
0
222
Oct ’24
WidgetKit widgets vanish in Montery with Xcode 16
We have recently added WidgetKit widgets to an existing product, and they've been working great on Macs using Big Sur and later. Recently, when installing a build on a Montery Mac, the widgets were no longer in Notification Center. After some trial and error, we discovered that if we build the project with Xcode 15.4, the widgets appear, but if we build with Xcode 16, the widgets vanish. This seems to happen on Macs running Big Sur or Monterey. The project is being built on Macs running Sonoma (both Apple Silicon and Intel). Is there a build setting in Xcode 16 that may have this effect?
1
1
183
2w
iOS widget crashing in body getter with -[NSTaggedPointerString identifier]: unrecognized selector sent to instance
Here is the code where the crash occurs var body: some WidgetConfiguration { IntentConfiguration(kind: WidgetKind, intent: ConfigurationIntent.self, provider: provider) { entry in // Parse config if let config = entry.configuration { if let fg = config.foreground, let fgColorId = fg.identifier, <---- let fgColors = AppSettings.sharedInstance()?.object(forKey: kWidgetForeground) as? [String:String], let fgColor = fgColors[fgColorId] { theme.textColor = Color.init(UIColor.fromHex(fgColor)) theme.iconColor = Color.init(UIColor.fromHex(fgColor)) } else { theme.textColor = .white//Color.primary theme.iconColor = .white//Color.primary } configuration is INIntent with foreground var which is INObject but some times it seems its not... and instead its NSTaggedPointerString unless I'm missing something here.
3
0
225
Oct ’24
How to disable Live Activity on Apple Watch while keeping it enabled on iPhone?
I'm using Live Activity features in my app, but I want to customize the user experience across different Apple devices. Specifically, I'd like to: Keep Live Activity enabled and functioning on the iPhone Disable or prevent Live Activity from appearing on the connected Apple Watch Is this level of device-specific control possible with Live Activity? If so, what's the best approach to implement this functionality? What I've tried: I've looked through Apple's documentation on Live Activity, but couldn't find specific information about device-level control. I've experimented with ActivityKit, but haven't found a clear way to distinguish between iPhone and Apple Watch when pushing updates.
4
0
406
Oct ’24
Users report that widgets are not working after iOS 18 update
I recently built a habit tracker app and got a few initial users. One of them reported that the widgets appear black and are not interactive. Does anyone know what might have happened to widgets in iOS 18 that could cause this issue? By the way, it works for me in the Simulator but not on a real device. How it supposed to work (simulator): https://i.giphy.com/media/v1.Y2lkPTc5MGI3NjExMWQ1N29sN2xvNnVjMjN5dGJqMHFxaGhtcGswaW43bTVvMnBmNW9wbSZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw/jevHq6JorR374YwuKF/giphy.gif How it actually works (real device): https://i.giphy.com/media/v1.Y2lkPTc5MGI3NjExaXNyZzRyYms4eG0yYzh0enF5ZXJyM29kN2VxMGszMHd4NTRkZnE1diZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw/k4mVTFE84kdztbwlDV/giphy.gif
1
0
307
Oct ’24
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
338
Oct ’24
Is there a way to know what size of icons is enabled in the home page?
Hey, i have an app that uses some calculations to replicate a transparent background in widgets, however given that in ios 18 we can now change the icons size to large, I wonder if there is a way to know what the user has currently selected and react to it? The workaround I have is that user needs to select a new config to switch the widget to large so re-calculations are done, but it would be nice if we there was a way for us to catch the new size.
0
0
188
Sep ’24
WidgetKit keep crashing and widgets not displaying
So I have a MacOS application that was working just fine before Xcode 16. The Widgets are not working anymore. The main application and the widgets share a file in a common App Group. The widget app now get a permission error when accessing the file. Also, the Widget Kit simulator keeps crashing. I also try to start a new project in Xcode, add a target with a Widget extension with an App Intent and run it, and it also crashes. Sometimes, it doesn't crash but just display the error: "Failed to load widget. The operation couldn't be completed. (WidgetKit_Simulator.WidgetDocument.Error error 2.). Edited to attach WidgetKit error log widgetKitError.txt
4
1
437
Sep ’24
Tinted widgets have an inset background in the widget gallery only
When the home screen is in tinted mode in iOS 18, the widget gallery seems to display widgets with the background inset from the edge of the widget (i.e. negative padding). You can see this behavior in the Apple News widget too, where the full-bleed content outside of the inset is very light. This only happens in the sample gallery, not when the widgets are placed on the home screen. For my widgets, this outer edge contains important content and the clipping behavior makes the widgets look poorly designed when viewed in the gallery. Is there any way to turn this behavior off and just show the widget normally in the gallery with no weird inset — the way it will actually display when added to the home screen? If it matters, my widgets are currently configured with: .contentMarginsDisabled() .containerBackground(for: .widget) { // ... (background color) */ }
2
0
225
Oct ’24
#Preview a Widget placeholder?
While I am able to use #Preview to preview a Widget, it seems to be not possible to easily preview a Widget placeholder. With a "classic" preview I can use .redacted(reason: .placeholder), but this has limitation e.g. it will ignore .contentMarginsDisabled() struct MyWidget_Previews: PreviewProvider { static var previews: some View { Group { MyWidgetView(entry: SimpleEntry(date: .now, emoji: "😀")) MyWidgetView(entry: SimpleEntry(date: .now, emoji: "😀")) .redacted(reason: .placeholder) } .previewContext(WidgetPreviewContext(family: .systemMedium)) .containerBackground(.white, for: .widget) } } If I use #Preview, the .redacted modifier won't work, and I seem to have to put it in the MyWidget implementation. #Preview(as: .systemMedium) { MyWidget() } timeline: { SimpleEntry(date: .now, emoji: "😀") SimpleEntry(date: .now, emoji: "🤩") } Am I missing something?
1
0
279
Sep ’24
Issue with Xcode 16 - Errors When Splitting Code for Widgets
I’m encountering an issue since I started using Xcode 16. I have a widget in my app, and I'm trying to organize the code by splitting it into different files for better structure. However, when I do this, I get an error: error: Unexpected input file: /Users/******/Desktop/TestApp/TestAppWidget/Provider.Swift (in target 'TestAppWidgetExtension' from project 'TestApp') I want to emphasize that if I keep all the code in one file, everything works fine. I've checked the Target Membership, and it's set up correctly. but I don't understand why this is happening only in Xcode 16. Has anyone else experienced a similar issue or has any ideas on why this is occurring? I would appreciate any help!
3
0
354
Sep ’24
How the iOS 18 Control Widget displays an AppIntentError to the user.
My app is an outdoor exercise tracking app that allows you to start exercising from the Control widget。 I want to prompt the user with an AppIntentError.PermissionRequired.location error when the user doesn't authorize Core Location permissions. When I throw error in the Intent, tap the Control widget doesn't do anything and doesn't give the user any indication of what's happening
2
0
266
Sep ’24