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()
}
WidgetKit
RSS for tagShow 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 you initiate a live activity from a Watch app? From what I can tell you can only do it from an iOS app and then have the Watch mirror it, is that true?
If you were builiding a standalone timer app for WatchOS for instance and wanted the timer to show up automatically in Smart Stacks when the app is in the background, is this possible?
Thanks
Im update my app to new version and the widget that use IntentConfiguration created in old version not working and still lay on homescreen. Is there any way to keep old widget working fine?
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.
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?
在执行完 INIntent 或者AppIntent的Shortcuts后,刷新 WidgetKit桌面小组件
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.
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.
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
It just won't debug any macos widget, not even the default template provided.
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.
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.
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
I solved before writing it up entirely and i accidentally hit enter and submitted it and cant delete the post
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) */
}
Hello. I am having trouble trying to create a control in control center view that opens a specific view in my app using AppIntents (iOS18 )and WidgetKit, can someone help me please? I feel like the original videos and documentations are incomplete.
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?
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!
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
In the app's Live Activity, Text (timerInterval:) is well displayed on Dynamic Island, but there seems to be a bug in Live Activity (Smart Stack in watchOS) that automatically transfers from iOS 18 to watchOS 11. Does anyone know about this?