The application was initially written in Swift, and we released an update where the app was rewritten in Flutter. Currently, we are adding a widget natively written in SwiftUI to the Home screen. The widget updates are managed by BGTaskScheduler. In BGTaskScheduler, an API request is made to fetch the latest data. The data is then processed to calculate an average value, which is subsequently sent to UserDefaults. The widget displays data fetched from UserDefaults. The minimum update interval is set to 30 minutes.
When testing the widget updates through a build in Xcode, the widget updates as expected at the specified interval. However, when this build was provided to users via TestFlight, the widget does not update for them. Could this issue be related to TestFlight’s resource limitations? Is there any guarantee that releasing this version will ensure the widget updates correctly for users?
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
I've encountered what appears to be a bug with widget background image tinting in SwiftUI. When using an image in containerBackground(for: .widget) to fill the entire widget, adding the .containerBackgroundRemovable(false) modifier breaks the widget's tinting behavior:
The background image becomes permanently tinted, ignoring any widgetAccentedRenderingMode(_ renderingMode: WidgetAccentedRenderingMode?) settings
Text elements become tinted even with .widgetAccentable(false) applied
Sample code:
struct MyWidget: Widget {
var body: some WidgetConfiguration {
AppIntentConfiguration(kind: "MyWidget", intent: MyWidgetIntent.self, provider: Provider()) { entry in
MyWidgetView(entry: entry)
.containerBackground(for: .widget) {
Image("background")
.resizable()
.widgetAccentedRenderingMode(.fullColor)
.scaledToFill()
}
}
.containerBackgroundRemovable(false) // This causes the issue
}
}
Workaround: I've managed to resolve this by using a ZStack with disabled content margins and passing the widget size through the entry. However, this seems like unintended behavior with the .containerBackgroundRemovable(false) modifier.
Has anyone else encountered this issue or found a better solution?
Device: iPhone 15 Pro
iOS Version: 18.1
Xcode Version: 16.1
So I have a button on a widget styled as seen below. I want this button to take up the entirety of the width, problem is, when it does so either using a frame(maxWidth: .infinity) or if I increase the horizontal padding, the button still only gets clicked if the user taps near the buttons center. Otherwise, it will open the app.
Relevant code:
Button(intent: Intent_StartRest() ){
Text("stop")
}
.buttonStyle(PlainButtonStyle())
.tint(.clear)
.padding(.vertical, 6)
.padding(.horizontal, 100)
.background(RoundedRectangle(cornerRadius: 30).fill(.button))
.foregroundStyle(.buttonText) // Just sets text color
.useAppFont(size: 18, relativeTo: .caption, weight: .bold) // Just sets font
Any pointers?
Environment:
Xcode16, iOS 18.1 official version
Background:
I created a control center widget using a custom sf symbol
Phenomenon:
When I first installed it, it displayed normally in the control gallery, but when I recompiled and installed it again, the icon disappeared when I looked at it again in the control gallery. I used Console to check the error log and found that its output was' No image named 'my_custom _symbol_name' found in asset catalog for/private/var/containers/Bundle/Application/F977FCFB-DA1C-4924-8613-50531CA2A364/MyDemoApp. app/PlugIns/MyDemoApp Extension. apex '. I found that this uuid was not consistent with the uuid I print during debugging, as if the control gallery had done some kind of caching;
Additionally, when I added my Control to the Control Center, it was able to display normally, and the only issue was with the Control Gallery
Attempted method:
-Using the system SF Symbol, it works fine and can be displayed normally in the control gallery after recompilation. However, once I switch another SF Symbols, the icons in the control gallery do not update after recompilation and installation
-Restarting the device, the same issue still persists
Is this a system bug or did I make a mistake? Looking forward to someone helping, thank you
My Code:
@available(iOSApplicationExtension 18.0, *)
struct MySearchControlWidget: ControlWidget {
let kind = "MySearchControlWidget"
let title = "My Title"
var body: some ControlWidgetConfiguration {
let intent = MyCommonButtonControlWidgetIntent()
StaticControlConfiguration(kind: kind) {
ControlWidgetButton(action: intent) {
Label("\(title)", image:"my_custom_symbol_name")
}
}
.displayName("\(title)")
}
}
Relevant docs: https://developer.apple.com/documentation/widgetkit/timelinereloadpolicy
I don't understand how .atEnd and .after works and how they differ.
So here's what I want: I want to display my widget then update it in 5 seconds. Now I know these examples show that I can use the .after policy like so:
let timeline = Timeline(
entries:[entry],
policy: .after(nextUpdateDate) // 5 seconds after now
)
But from reading the docs, .atEnd means: "A policy that specifies that WidgetKit requests a new timeline after the last date in a timeline passes."
So why can't we do:
let timeline = Timeline(
entries:[entry1, entry2], // entry 2 has date 5 seconds after
policy: .atEnd
)
I tried this and it does not seem to work. When I say I tried, I just had an onAppear on my widget view to print out the entry dates, and the entry 5 seconds later never prints. So what does .atEnd actually do? What happens if we put .atEnd with 1 entry?
In the Explore enhancements to App Intents WWDC video at the 11 minute mark I see this UI in the Widget configuration.
My question is, how do I configure my Widget to use this UI in the intent configuration? I tried using all different sorts of types and am unable to reproduce it in my app
I have an app and widget that share access to a SwiftData container using App Groups. I have implemented a SwiftData migration plan, but I am unsure whether I should allow the widget to perform the migration (in addition to the app). I am concerned about two possible issues:
If the app and widget are run at approximately the same time (e.g. the user taps Open after doing a manual update in the App Store), then both the app and widget might try to perform the migration at the same time, which could lead to race conditions / data corruption.
If the widget is first to run but the widget gets suspended for some reasons (e.g., iOS decides it's using too many resources), then the migration might be suspended leaving the database in an corrupted state.
To me, it feels like the safest option is to only allow the app itself to perform the migration – this will ensure that the migration can only happen once in a safe state. However, this will lead to problems for the widget. For example, if the user does not open the app for several days after an automatic update, the widget will be in a broken state, since it will not be able to open the container until it has been migrated by the app.
Possible solutions I'm considering:
Allow both the app and widget to perform the migration and cross my fingers. (Ignore Issue 1 and Issue 2)
Implement some kind of UserDefaults flag that is set to true during migration, so that the app and widget will avoid performing the migration concurrently. (Solves Issue 1 but not Issue 2)
Only perform the migration in the app, and then add code to the widget to detect which container version the widget has access to, so that the widget can continue to work with a v1 container until the app eventually updates it to a v2 container. (Solves Issue 1 and Issue 2, but leads to very convoluted code – especially over time)
Things I'm unsure about:
Will iOS continue to use v1 of the widget until the app is opened for the first time, at which point v2 of the widget is installed? Or does iOS immediately update the widget to v2 on update? Does iOS immediately refresh the widget timeline on update?
Does SwiftData already have some logic to avoid migrations being performed twice, even from different threads? If so, how does it respond if one process tries to access a container while another process is performing a migration?
Does anyone have any recommendations about how to handle these possible issues? What are best practices?
Cheers!
Hello, I have a small lightweight macOS application that includes a medium widget but the widget does not update with new data as often as I'd like. I understand that in apple's WidgetKit documentation they mention that apple controls when the widget updates due to battery life concerns, but I'd like to know if theres any way at all to control when the widget updates or when I think it makes sense to do so if I am not able to control how often it refreshes new data.
https://github.com/Alexx1105/MacStat-v2.1
I have an app with a shared internal framework, a main app target, and a widget target. In my shared framework, I have an AppIntent, FooIntent. In addition, I have an AppIntentPackage
public struct FooIntentsPackage: AppIntentsPackage { }
also in the framework. Finally, in the widget target, I reference that package:
struct FooAppIntents: AppIntentsPackage {
static var includedPackages: [any AppIntentsPackage.Type] { [ FooIntentsPackage.self ] }
}
However, when I run this, I get a bunch of these errors:
metadata `_$s8Internal15FooAppIntentsV' did not match any imported symbol.
I've tried turning off Strip Linked Product in both the Framework and the Widget, to no avail. Any ideas?
I recently built a widget with WidgetKit. When I bulding app from Xcode on the simulator widget appears, but when I install app from TestFlight widget is missing. 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.
Does anyone else have a problem that with iPad OS18.2 beta, its not possible to set or change the wallpaper either from the lock screen or from settings.
Alost means that you can’t add Widgets to the lock screen.
Is this a bad update on my iPad or is this a bug?
Hi,
Firstly: The whole question is about MacCatalyst (in IOS it works as intended)
In my Maccatalyst app I want to share Userdefaults between app and widget. I have added an app group to the widget and the app and have set up Userdefauls accordingly.
Here is the problem:
Xcode claims that the app group should start with "group.***" because Catalyst is based on iOS. If I do so, my Catalyst app rises the "App wants to access data from other apps" requester on EVERY launch. So, I can't use it in production. Even if I would accept the requester, the widget isn't able to access the defaults at all because it does not rise that requester, but silently ignores the access.
In contrast, if I setup the app group name with our TeamID (instead of group.*) then the requester vanishes, but Xcode does not accept it, issuing a warning and displaying the app group in red. I don't think this is advisable 'state' for production code. Even then widget can't see the data either.
What is the recommended way of sharing Userdefaults between Catalyst app and Catalyst Widget (not the iOS widget which displays the "open on iPhone warning" when clicked) on macOS ?
Thanks
(Also have a case ID, 9879068)
We have an app that user use to check in/out from work for example. We have a button in-app do do this. Now I'm trying to add buttons to our widgets and our new live activity so that users don't have to open the app.
It's crucial that the live activity and widgets always show the exact same state.
Otherwise it'll look pretty bad if a user has both a live activity and a widget showin at the same time.
However, we have noticed that sometimes, pressing the button in the live activity, running the app intent, will not always make the widget update (we call reloadAllTimelines()). The other way around, i.e. press the button on widget to update live activity always works. (they both call the same app intent)
When running it in debug mode on a phone from Xcode, it always works, but when running it just on the phone it's unreliable.
My first thought was, of course, that's related to the widget "budget", but according to the docs HERE, it should not be applied when interacting with a widget, calling an app intent.
My question: HOW can I make my widget reliably refresh using an app intent invoked from a live activity??
I have a ready small project with simple buttons and trace labels that display this issue that I'm happy to supply to someone.
Hello,
I have an app in AppStore "Counter Widget". https://apps.apple.com/app/id1522170621
It allows you to add a widget to your homescreen/lockscreen to count anything.
Everything works fine except for one scenario. iOS 18+
I create 2 or more widgets for one counter. For example, medium and small widgets.
I click on the widget button to increase or decrease the value.
The button in the widget uses Button(intent: AppIntent) to update the value and calls WidgetCenter.shared.reloadAllTimelines() to update the second widget for the same counter.
For iOS 18 in this particular scenario, you don't even have to call the WidgetCenter.shared.reloadAllTimelines(). iOS already knows that there is a widget with the same INIntent settings and will update it itself.
Both widgets are updated and show the new value. Everything is correct.
Now on the homescreen I open the widget configuration for one of the widgets to change the INIntent for the widget. For example, i change the background to wallpaper. This is just a skin for the widget, and the widget is associated with the same counter value as before.
As in (2), I click the widget button to increase or decrease the value.
But now only one widget is updated. iOS ignores my call to WidgetCenter.shared.reloadAllTimelines() and does not update the second widget connected to the same counter.
As I found, iOS, when I call WidgetCenter.shared.reloadAllTimelines() from the widget itself, updates other widgets only if INIntent is absolutely equal for them.
Overriding isEqual for them did not help. That is, I cannot specify which fields from my INIntent can be ignored during such an update and consider that widgets are equal and need to be updated. Obviously iOS make this compare outside my code.
The main problem is that when the user adds a widget to the lock screen and increases and decreases the value there. After that, he opens the home screen and the widget there is not synchronized with the value from the widget on the lock screen.
How to solve this problem?
macOS: Sequoia
Xcode: 16.1
I am working on a macOS app and it has a widget feature.
When I use Swift 6 (Build Settings > Swift Language Version) in IntentExtension, the intent configuration won't show up in macOS Sequoia.
If I downgrade to Swift 5, it works without any other changes.
Is it a bug or am I missing something? How can I use Swift 6 with IntentExtension.
I created an intent for a configurable widget that lets users choose an option for a parameter called "domain."
I've successfully loaded the selectable items for this parameter using the following code:
import Intents
class IntentHandler: INExtension, ConfigChartIntentHandling {
func provideDomainOptionsCollection(for intent: ConfigChartIntent) async throws -> INObjectCollection<Domain> {
let prefs = UserDefaults(suiteName: "group.name")
let domains = prefs?.stringArray(forKey: "domains")
if let domains {
let optionsCollection = domains.map { Domain(identifier: $0, display: $0) }
return INObjectCollection(items: optionsCollection)
} else {
// If no options, provide an empty list or a default option
return INObjectCollection(items: [])
}
}
}
The issue occurs when I select a value for the "domain" parameter. Each time I select a value and then reopen the configuration modal, the field reverts back to "Choose." Here's a screenshot illustrating the behavior:
Additionally, the widget doesn’t refresh after I change the "domain" value. However, another parameter using an enum ("Stats Type") works as expected.
Is there something I might be missing?
My Environment:
MacOS Sonoma
XCode 15.4
I made a LockScreen ControlWidget with CameraCaptureIntent, but I found launch my main app from Control Widget, SceneDelegate will be called like below:
sceneWillEnterForeground
sceneDidBecomeActive
sceneWillResignActive
sceneDidBecomeActive
sceneWillResignActive be called, is it normal?
it make my app camera launch with a delay.
I noticed that with iOS 18, when adding a widget to the Control Center, there is now some "grouping system". I'm interested in the Capture group, which contains native widgets from Apple as well as third party apps like Instagram and Blackmagic cam, widgets in this group open the camera. My widget also opens the camera in my app, how can I add it to this group?
Xcode: 16.1
macOS: Sequoia
When I run widget preview, I got the following errors
CoreData: error: Store failed to load. <NSPersistentStoreDescription: 0x156237310> (type: SQLite, url: file:///Users/user/Library/Group%20Containers/group.com.app.name/Library/Application%20Support/default.store) with error = Error Domain=NSCocoaErrorDomain Code=256 "The file couldn’t be opened." UserInfo={reason=Unknown failure to access file: 1} with userInfo {
reason = "Unknown failure to access file: 1";
}
Unresolved error loading container Error Domain=NSCocoaErrorDomain Code=256 "The file couldn’t be opened." UserInfo={reason=Unknown failure to access file: 1}
with this code
let sharedModelContainer: ModelContainer = {
let schema = Schema([Company.self, Person.self])
do {
return try ModelContainer(for: schema, configurations: [.init(isStoredInMemoryOnly: false)])
} catch {
fatalError("error: \(error)")
}
}()
Does anyone know why this happens and how to fix this?
Hi devs,
my app has control center widgets and interactive widgets, both are using the same app intent to update sharing status (App Group's UserDefault).
When the app is running in the background, control center widget and interactive widgets can be reloaded with correct status. However, if the app is not running in the background, I tap the interactive widget and the interactive widget can reload with correct status but the control center widget can't. Vice versa, the control center widgets can reload with correct status but the interactive widgets can't.
struct ChangeAppStatusIntent: AudioRecordingIntent, CustomIntentMigratedAppIntent, PredictableIntent, LiveActivityIntent, SetValueIntent {
... // data and setup
@MainActor
func perform() async throws -> some IntentResult {
// change the AppGroup data for app status
WidgetCenter.shared.reloadAllTimelines()
ControlCenter.shared.reloadAllControls()
}
}
does any way to fix this issue?