There is an issue that widgets are deleted during deployment to xcodecloud. Only reproduced on iOS 16.6 devices. No problem with manually deployed cases.
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
My app's Widgets on iPhone rely on access to the Health Store to update. This makes them appearing in the new StandBy mode not a good experience as they never update.
Is there a way to opt out of this mode but keep the options for my users to put Widgets on their home screen?
Thanks
I'm encountering an intriguing issue with interactive widgets and the AudioPlaybackIntent on my device.
Specifically, my problem arises when the device is set to silent mode. Despite the silence setting, selecting the category .playback continues to play sounds, which is the expected behaviour.
However, when I opt for alternative categories like .ambient or .soloAmbient, these widgets cease to produce sound, even when the device is in ringer mode.
I would appreciate any insights, solutions, or discussion on this matter within the Apple forum community.
// This code snippet allows audio to play in widgets with interactive buttons, even in silent mode.
try? AVAudioSession.sharedInstance().setCategory(.playback, mode: .default, options: [])
try? AVAudioSession.sharedInstance().setActive(true)
// Conversely, this code snippet prevents audio playback in widgets with interactive buttons, even in silent mode.
try? AVAudioSession.sharedInstance().setCategory(.ambient, mode: .default, options: [])
try? AVAudioSession.sharedInstance().setActive(true)
Works as expected on the Simulator, but encounters issues when tested on a physical device using Xcode 15 Beta 8
Hello Everyone,
I'm working on creating an audio playback widget for my app, aiming for functionality similar to the Apple Music widget. Specifically, I've implemented a play button in my widget that triggers an AudioPlaybackIntent. This intent then interacts with a singleton class that manages my AVAudioPlayer.
The issue I'm facing is that the AVAudioPlayer instance in my main app and the instance in my widget extension don't seem to share the same state. I've noticed that the Apple Music widget is capable of showing real-time changes (eg. stopping music from command center, stops it on widget UI), which implies that it has some way of sharing the playback state between the main app and the widget.
How can I achieve shared state between the main app and widget for my AVAudioPlayer instance?
Is there a specific approach or API that Apple Music uses to make this happen?
I've migrated my ClockKit complication to WidgetKit in my app.
Everything is working fine when I run the app on watch OS 9.4 simulator with Xcode 14.3.1
But when I compile withe Xcode 15 Beta 8 ( or beta 7, 6..), the invalidateConfigurationRecommendations() does not work anymore.
the Recommendations() func from the IntentTimelineProvider is not called and thus the complication/widget list is not updated for the user
The rest is working fine, all widgets are well displayed, and I can still add / change any widget from the original list.
Running the app on a watchOS 10 simulator using Xcode 14.3.1, I've succeeded to see an error message :
[widget] invalidateConfigurationRecommendations() - error reloading supported intents: Process not authorized to make this timeline request
But I could not find any information about this error
I've also tried by migrating the SiriIntent to AppIntent on Xcode 15 Beta 8, but the issue persists, Recommendations() is still not called upon invalidateConfigurationRecommendations()
The application project is composed of :
iOS App
watchKit App
WatchKit Extension
Widget Extension (for IOS App)
Widget Intent (for iOS App)
Complication Extension (for watchOS widgets)
Looking desperately how to fix this...
Thanks for any help
Is it possible to tell in your code if the app was launched from an app intent action in a widget.
In my SwiftUI code it has something like Button(intent: MyIntent()) I want to be able to tell when the user has clicked on the button to launch the app, because I need some different setup code to run before the intent perform method is called.
Thanks
Hi guys,
We have received several reports from our users: after deleting the watch app, the complications still remain.
It seems system cache the config and forget to remove after deleting the app.
(Our app is useing WidgetKit as complications)
What does it mean?
Please adopt cont...
The error
The widget background view is missing. Please ensure that you have called the `containerBackground(for: .widget) {…}` modifier in your widget view.
I do use .containerBackground(Color.blue.gradient, for: .widget), but it's no longer working in Xocde beta 8
ios 17 interactive widget api call in background
An API request is being made through Interactive widget in iOS 17.0 version. The desired situation is to request an API through the widget's Intent and receive a response from the server. (Because it is opened from Intent, the app does not open.) But a problem occurred here.
When both the main app and the widget are built, the above request works well. However, even if the build is stopped, the request is made normally if the app is in the foreground state.
However, when the app is in the background, API calls are not made through Intent. How can I solve this?
Desired situation:
API call request through App Intent under any network condition when the app is turned off (may not be reflected separately in the widget)
Problem Situation:
API call through Celluar data fails when the app is turned off.
What's currently working properly:
Successful API call through Wi-Fi when the app is turned off
Api call is successful under any network conditions when the app is turned on.
I'm following Displaying live data with Live Activities and adding support for the Dynamic Island in an app with an existing widgets extension. However, I'm unable too get it to build
import SwiftUI
import WidgetKit
@main
struct PizzaDeliveryActivityWidget: Widget {
var body: some WidgetConfiguration {
ActivityConfiguration(for: PizzaDeliveryAttributes.self) { context in
// Create the presentation that appears on the Lock Screen and as a
// banner on the Home Screen of devices that don't support the
// Dynamic Island.
// ...
} dynamicIsland: { context in
// Create the presentations that appear in the Dynamic Island.
// ...
}
}
}
as I get the errors
Generic parameter 'Expanded' could not be inferred
and
Result builder 'DynamicIslandExpandedContentBuilder' does not implement any 'buildBlock' or a combination of 'buildPartialBlock(first:)' and 'buildPartialBlock(accumulated:next:)' with sufficient availability for this call site
This is even if I supply a dynamicIsland closure of
DynamicIsland {
EmptyView()
} compactLeading: {
EmptyView()
} compactTrailing: {
EmptyView()
} minimal: {
EmptyView()
}
What am I missing? My project's minimum deployment target is iOS 16.1.
My app features two kinds of widgets, let's call them kind A and kind B.
I have both A and B widgets on my Home Screen. When I tap the button on widget A (associated with App Intent), I expect widget B to also reload.
However, if you call WidgetCenter.shared.reloadAllTimelines() inside the perform() method of the AppIntent, the timeline of widget B does not reload immediately. This issue only occurs on a physical device and is not consistently reproducible. On a simulator, however, widget B reloads as expected.
FB13152293
Hi there,
When using WidgetKit, should I should fetch my SwiftData main app's database in the TimelineProvider or directly on the widget's view?
Also, my understanding is that the widget view's code is run during the archiving process and not when the view first appears on the user's device. So, is it true that accessing in the TimelineProvider vs. accessing in the view will both run at approximately the same time, and thus will return the same DB results?
Best,
Taylor
Hello,
I noticed that the layout of compact Dynamic Island on iOS 17 is incorrect. The edge of the circle shape is unable to be aligned with the edge of Dynamic Island.
However, the layout in Xcode Preview is just perfect. And this is also the same layout on previous iOS 16:
If you try to workaround the issue by adding an offset to the view, it will be cropped by a misaligned circle.
I want to check whether the widget is at Standby mode in TimelineProvider.
I thought showsWidgetContainerBackground == false means the widget is at Standby mode, referring to 'WWDC 2023 Bring widgets to new places'.
struct Provider: TimelineProvider {
func getTimeline(in context: Context, completion: @escaping (Timeline<Entry>) -> ()) {
let isBackgroundShown = context.environmentVariants.showsWidgetContainerBackground // Error: Cannot assign to property: 'showsWidgetContainerBackground' is a get-only property
...
completion(timeline)
}
...
}
But in TimelineProvider, I can't get context.environmentVariants.showsWidgetContainerBackground because it is get-only property.
This is because context.environmentVariants adopts @dynamicMemberLookup with WritableKeypath<EnvironmentValues, T>.
Is there any chance to detect the widget is at Standby mode in TimelineProvider? Is it possible or not?
Any suggestion would be very grateful. Thank you.
AFAIK new iOS 17 widgets APIs are not supported on watchOS, which is a shame because it limits what kind of apps we can do for Apple Watch. I can see this can be disabled for the Smart Stack but for the single .accessoryRectangular performance shouldn't be an issue. Upvote this thread if you would like interactive widgets on watchOS.
I want to adjusts the color saturation of swiftUI view to 0%.
In iOS 17 widgets, it doesn't work however it is working fine for widgets in iOS16 and prior and in application target
Hello all,
Working on Xcode 15 GA. I'd like to archive my new iOS 17 project, which works properly on iOS and macOS (includes SwiftData library, new WidgetKit extension and StoreKit).
However, when I'm trying to archive the project (either for iOS or macOS) I get an error as follows -
"Error opening _.stringsdata for output: File name too long.
I tried everything - still happens. When I'm looking inside the build folder, I see that this error probably related to new @__swiftmacro files.
Have no idea how to proceed from here. Blocked from distributing my new app. Any idea?
Thanks a lot!
Dudi
Hello, I want to make an IOS battery widget application using SwiftUI and WidgetKit. I researched a lot, but I could not find how to capture battery data for IOS. I need to access Battery Cycle, battery health and charging data. How can I do this?
I want to share UserDefaults between main App and macOS Widget, in iOS I can do it using AppGroups, but how to do it between macOS Widget and main App, because macOS widget's AppGroup require to use "Team Identifier" as prefix and main App's AppGroup require prefix to be "group" so how can I share UserDefaults between the two?
I'm in the process of migrating one of my app's Apple Watch complications from ClockKit to WidgetKit.
In my ClockKit complications, there are some cases where a show the relative time since the last event in the app (for example, "25MIN").
With ClockKit, this was quite straightforward using a CLKTextProvider designed for this exact purpose:
CLKRelativeDateTextProvider(date: date, style: .offsetShort, units: [.hour, .minute])
This has always worked great, since it lets me specify that hours and minutes should be used, but not seconds, since they're not relevant here.
How can I accomplish the same thing with WidgetKit and SwiftUI?
The closest thing I've found is this:
Text(date, style: .relative)
It shows, for example: 14MIN 8SEC
This is not what I want, since it shows seconds. It makes the complication look messy with all the extra information, and is distracting because it updates every second until an hour has passed.
I suppose I could write my own logic to create a new timeline entry every minute to show the number of hours and minutes since the last update, but since CLKTextProvider works so nicely I wanted to check whether there is some way to accomplish the same thing without creating a new entry for every minute.
There seem to be some more customizable options with date formatters, but I haven't found a way to combine this with the SwiftUI version that updates automatically on the Apple Watch face:
https://developer.apple.com/documentation/foundation/date/relativeformatstyle/3766585-presentation