Bring widgets to life

RSS for tag

Discuss the WWDC23 Session Bring widgets to life

View Session

Posts under wwdc2023-10028 tag

20 Posts
Sort by:
Post not yet marked as solved
3 Replies
957 Views
With the new interactive widgets brought by iOS 17, is it possible to indicate that an action (button tap or toggle use) has been triggered by firing an Haptic feedback to the user?
Posted
by Clem23.
Last updated
.
Post marked as solved
4 Replies
1.1k Views
When applied .contentMarginsDisabled() modifier to WidgetConfiguration, Widget extension crashes on launch in Xcode 15 Beta 3. struct TestWidget: Widget { let kind: String = "TestWidget" var body: some WidgetConfiguration { return IntentConfiguration(kind: kind, intent: TestIntent.self, provider: TestProvider()) { entry in TestView(entry: entry) } .configurationDisplayName("TestWidget") .description("This is TestWidget.") .supportedFamilies([.systemMedium]) .contentMarginsDisabled() // << Here } } Though it works in Xcode 15 Beta 2. Anyone facing same issue ?
Posted Last updated
.
Post marked as solved
2 Replies
1.5k Views
I want to be able to start/stop audio from my interactive widget. But when I try to start playback with my AppIntent, I get the error, ATAudioSessionClientImpl.mm:281 activation failed. status = 561015905 This indicates the app isn't set up properly for background audio, but it has Audio, AirPlay, and Picture in Picture checked in Background Modes. Is this an intentional limitation of 3rd party widgets? The Apple Music widget is able to start and stop audio without the app being in the foreground. Can third party apps do it too?
Posted Last updated
.
Post not yet marked as solved
3 Replies
4.3k Views
Hi, I need to keep supporting iOS16 for my widgets. I'm having a problem using the iOS17 'containerBackground' API. Ideally I would use a view extension: extension View { func adoptableWidgetBackground(_ color: Color) -> some View { if #available(iOS 17.0, *) { containerBackground(for: .widget) { color } } else { background(color) } } } But this gives an error: Branches have mismatching types 'some View' (result of 'Self.containerBackground(for:alignment:content:)') and 'some View' (result of 'Self.background(_:alignment:)') If I try to use this directly on the 'body' view modifier like this: if #available(iOS 17.0, *) { .containerBackground(for: .widget) { ContainerRelativeShape().fill(Color.init(UIColor.quaternarySystemFill)) } } else { .background(ContainerRelativeShape().fill(Color.init(UIColor.quaternarySystemFill))) } This doesn't work either. Instance member 'containerBackground' cannot be used on type 'View' How do I use this correctly?
Posted
by zulfishah.
Last updated
.
Post not yet marked as solved
5 Replies
1.7k Views
I have AppIntent code which lives in my app package that can not easily be decoupled and migrated into its own standalone framework or extension. This is because this intent has some action that relies on my app's network and core data stack. I'd like to expose this existing intent in some way to a Button in a widget, but so far I have not had success. Is this currently possible with AppIntentPackage or some other means? Is there a way I can use AppIntents to pass a message back to the app? How should I approach this? Thank you!
Posted
by reed.1325.
Last updated
.
Post not yet marked as solved
0 Replies
758 Views
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.
Posted
by SOEY.
Last updated
.
Post not yet marked as solved
0 Replies
565 Views
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
Posted Last updated
.
Post not yet marked as solved
8 Replies
1.8k Views
While it's wonderful that the Widget provides animation and interaction capabilities, I've encountered a slight issue with the animation when using it to display a countdown. It tends to become bothersome. Is there a method to disable the animation?
Posted Last updated
.
Post not yet marked as solved
4 Replies
1.4k Views
I have an App Group shared between my app and its widgets. I have SwiftData's @Model, updated from the widget intent's perform() method and displayed on the app and the widget. @MainActor func perform() async throws -> some IntentResult { let context = try ModelContainer(for: MyModel.self).mainContext let myModel = try ModelContainer(for: MyModel.self).mainContext.fetch( FetchDescriptor<MyModel>(predicate: #Predicate { // The predicate is not the problem. }) ).first myModel?.functionThatModifiesMyModel() return .result() } Both the app and the widget SwiftUI views access to the model using Macros. @Environment(\.modelContext) var context @Query(sort: \.whatever) var myModel: [MyModel] But the data is never correct in the app code (the widget's data is updated correctly using the intent). Why doesn't the model make it to the app?
Posted
by serg-ios.
Last updated
.
Post not yet marked as solved
1 Replies
593 Views
In widgets when the button is tapped, we will get a call back to perform() func in app Intent. After this perform func execution is completed, timelineProvider will be called. Likewise, what is the option to update the live activity value once perform() is called in appIntent? I tried to access the live activity instance from the extension into the app, but it is nil so, I can't able to update my live activity.
Posted
by abishak.
Last updated
.
Post not yet marked as solved
1 Replies
522 Views
I have created a widget and added a button in its body like this: Button("Tap me: ", intent: TaskIntent()). If I compile the TaskIntent in both the app and the widget, when tapping the button, it open the app and that's all, 'perform' is not called at all. If I compile the TaskIntent only in the widget, when tapping the button, it does nothing, 'perform' is not called either. Is there any special sauce needed to run the 'perform' of the AppIntent attach to the button?
Posted Last updated
.
Post not yet marked as solved
1 Replies
746 Views
My app allows users to store URLs for future reference. It also has widgets that display these saved items. I want to make these widgets interactive by opening the linked content in Safari without having to open the main app. The issue is that UIApplication.shared.open is not available in app extensions. And this is a problem since widgets are app extensions. Are there alternative methods to accomplish this scenario, or is it currently unsupported?
Posted Last updated
.
Post marked as solved
1 Replies
1k Views
Hello, In WidgetKit, I have to write multiple #Preview macros for each family the widget supports. So is there any better way to write the #Preview? (Although I can use the legacy PreviewProvider but it does not support timeline to test transition animation.) #import WidgetKit #import SwiftUI struct DailyCaffeineWidget: Widget { ... } @available(iOS 17.0, *) #Preview("Inline", as: .accessoryInline) { DailyCaffeineWidget() } timelineProvider: { previewTimelineProvider() } @available(iOS 17.0, *) #Preview("Circular", as: .accessoryCircular) { DailyCaffeineWidget() } timelineProvider: { previewTimelineProvider() } @available(iOS 17.0, *) #Preview("Rectangular", as: .accessoryRectangular) { DailyCaffeineWidget() } timelineProvider: { previewTimelineProvider() } @available(iOS 17.0, *) #Preview("Small", as: .systemSmall) { DailyCaffeineWidget() } timelineProvider: { previewTimelineProvider() } @available(iOS 17.0, *) #Preview("Medium", as: .systemMedium) { DailyCaffeineWidget() } timelineProvider: { previewTimelineProvider() } ...
Posted
by Gong.
Last updated
.
Post not yet marked as solved
1 Replies
1.5k Views
Inside a widget, there is a button, Button(intent: AnAppIntent()) { // Button's label. } // It seems this modifier does not add any value. .invalidatableContent() connected to an AppIntent. struct AnAppIntent: AppIntent { static var title: LocalizedStringResource = "An AppIntent" init() { // AppIntent required init. } func perform() async throws -> some IntentResult { // Never called when the app is running. return .result() } } The button calls AppIntent's perform() when tapped, and it consequently updates the widget UI (with or without the modifier .invalidatableContent()) only when the app is closed completely. If the app is alive in the background, perform() is not called, and the widget UI never updates. The user must explicitly dismiss the app to make the widget work as expected. The problem may be in the timeline used. struct SimpleEntry: TimelineEntry { let date: Date } struct Provider: TimelineProvider { func placeholder(in context: Context) -> SimpleEntry { SimpleEntry(date: Date()) } func getSnapshot(in context: Context, completion: @escaping (SimpleEntry) -> ()) { completion(SimpleEntry(date: Date())) } func getTimeline(in context: Context, completion: @escaping (Timeline<Entry>) -> ()) { var entries: [SimpleEntry] = [] // Generate a timeline of five entries an hour apart, starting from the current date. let currentDate = Date() for hourOffset in 0 ..< 5 { let entryDate = Calendar.current.date(byAdding: .second, value: hourOffset, to: currentDate)! entries.append(SimpleEntry(date: entryDate)) } let timeline = Timeline(entries: entries, policy: .atEnd) completion(timeline) } } However, if the problem were the timeline, the widget would not work with the app dismissed. Any idea on how to keep interactive widgets always working?
Posted
by serg-ios.
Last updated
.
Post not yet marked as solved
1 Replies
717 Views
I want to create interactive watch face widget in a way, so user can see some data from my app on the Watch Face widget and then tap on the widget (complication) to change the data without moving inside the app. Does it possible? Or after the tap user always will be moved inside my app? I saw interactive widgets was introduced for iOS and macOS on WWDC23 https://developer.apple.com/videos/play/wwdc2023/10028. But can smth like that be developed for WatchOS?
Posted
by Redwerk.
Last updated
.
Post not yet marked as solved
1 Replies
1.8k Views
Can't compile existing project with new #Preview macros. Get: 'Preview' is only available in application extensions for iOS 17.0 or newer And because macros generate struct I can't use #available to fix this. Does anyone have any ideas how to fix this? I guess the only solution is to create new macros that will work like #available(iOS 17) { code } and remove the code for older iOS?
Posted Last updated
.