Bring widgets to life

RSS for tag

Discuss the WWDC23 Session Bring widgets to life

Posts under wwdc2023-10028 tag

19 Posts
Sort by:

Post

Replies

Boosts

Views

Activity

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
807
Sep ’23
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
607
Sep ’23
Cannot Start Audio Playback from Interactive Widget (iOS 17)
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?
2
1
1.7k
Oct ’23
'Perform' is never called from iOS17 Widget
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?
1
1
565
Aug ’23
No Call for Live Activity to update
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.
1
0
627
Aug ’23
Any better way to write multi-family Widget #Preview macro?
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() } ...
1
2
1.1k
Jul ’23
WidgetExtension Crashes on launch in Xcode 15 Beta 3
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 ?
4
0
1.1k
Oct ’23
Why don't interactive buttons in iOS 17 widget call AppIntent perform() when the app running?
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?
1
1
1.6k
Jun ’23
Opening a Safari URL from an interactive widget with AppIntents
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?
1
1
811
Jul ’23
Is there any way to expose an AppIntent that lives in the app package or an AppIntentExtension to a widget?
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!
6
5
1.8k
Sep ’23
WatchOS: tap action for watch face complication
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?
1
0
740
Jun ’23
Using containerBackground with iOS16 deployment
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?
3
1
4.6k
Oct ’23
can't use #Preview for widgets code compatible with iOS < 17
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?
1
3
1.9k
Jun ’23