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

Muting Audio in Interactive Widgets with AudioPlaybackIntent When Device is in Silent Mode
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
0
0
697
Sep ’23
Shared AVAudioPlayer State Between App and Widget: How does Apple Music Do It?
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?
3
3
535
Sep ’23
[widget] invalidateConfigurationRecommendations() - error reloading supported intents: Process not authorized to make this timeline request
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
4
1
900
Sep ’23
ios 17 interactive widget api call in background
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.
0
0
909
Sep ’23
Implementing Dynamic Island support - Generic parameter 'Expanded' could not be inferred
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.
2
0
1.7k
Sep ’23
Interactive Widget: unable to reload timeline from AppIntent
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
3
3
681
Sep ’23
WidgetKit - Should I access my SwiftData cloud kit synced DB from TimelineProvider or the Widget's view?
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
1
2
620
Oct ’23
Incorrect compact Dynamic Island layout on iOS 17
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.
5
5
1.5k
Oct ’23
How can I detect Standby mode widget in TimelineProvider?
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.
0
0
394
Sep ’23
Interactive widgets on Apple Watch
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.
0
1
366
Sep ’23
Xcode 15 archive failed - file name too long
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
4
2
2k
Oct ’23
How can I re-create a CLKRelativeDateTextProvider in a WidgetKit complication?
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
4
0
781
Oct ’23