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

Can't Apple Watch App Widget Complication to Update
Hello, So I made a VERY simple watch app that basically tracks drinks for a project. I was going to go with complications, but they seem to be outdated. Lo and behold Widgetkit! I set up a VERY simple widget that shows the drink count in my app, and it works AMAZINGLY well in Xcode using the WidgetCenter.shared.reloadAllTimelines() function. However, on actual hardware, the widget will only update to the new drink count if I lock and unlock the watch. It does update overtime in accordance to the widget timeline, but I'd rather it update while the user is in app (no update budget used) and in real time, so the user doesn't see their drink count from 2 minutes ago after they've already added a drink. Keep in mind this is a WatchOS app, there is no iOS app it's attached to. Is there anyway I can refresh or re-render the widget like how the Lock/unlock watch does? Anyone else having this issue? I see a few options, but they involve creating an iOS app with background enabled.. I'd like to keep this simple and a watchOS app. Thank you
4
1
1.3k
Aug ’23
iOS Widget not available in Widget Search on iOS 16
We are running into a major issue with building an iOS Widget. iOS Widgets are basically large informational app icons you can pin to your iPhone home screen (What is a widget?). iOS widgets were introduced in iOS 14. We’ve finished building our iOS widget. However, when half of our users attempt to search for our widget after downloading our app, our widget is not showing up in the widget search results. For the other half, it works fine. This seems to be somewhat of a bug from Apple, as it is affects other widget apps (Apple Thread, the problem exists for large widget apps also). It seems like we are having this issue far more, percentage-wise, than other widget apps. I’ve searched through nearly every resource online (StackOverflow, etc.), which is why I’m posting a question now. Things like deleting the app and reinstalling, restarting the phone, etc. have not been a fix either for these problematic users. It doesn't seem to be tied to any iOS version (14, 15, etc.). As I have iOS 15, and it works fine. But, some users with iOS 15 are getting the bug. Has anyone ran into this issue where a widget is not searchable? How did you fix it? Any resources are appreciated as I am at a major blocker right now. Since my app is primarily based on iOS widgets, this makes it basically unusable for certain users.
1
2
760
Oct ’23
Xcode 14.3 - Multiple commands produce swiftsourceinfo
Hello, I am with a long running project that is written in Objective-c and Swift (more). I have added a widget target extension to the project, but can't compile since there is this issue: What is the potential problem and how to solve it? = swiftsourceinfo Multiple commands produce '.../Build/Products/Debug-iphonesimulator/MyApp.swiftmodule/Project/arm64-apple-ios-simulator.swiftsourceinfo' Target 'MyApp' (project 'MyApp') has copy command from '.../Build/Intermediates.noindex/MyApp.build/Debug-iphonesimulator/MyApp.build/Objects-normal/arm64/MyApp.swiftsourceinfo' to '.../Build/Products/Debug-iphonesimulator/MyApp.swiftmodule/Project/arm64-apple-ios-simulator.swiftsourceinfo' Target 'MyAppWidgetsExtension' (project 'MyApp') has copy command from '.../Build/Intermediates.noindex/MyApp.build/Debug-iphonesimulator/MyAppWidgetsExtension.build/Objects-normal/arm64/MyApp.swiftsourceinfo' to '.../Build/Products/Debug-iphonesimulator/MyApp.swiftmodule/Project/arm64-apple-ios-simulator.swiftsourceinfo' = arm64-apple-ios-simulator.abi.json Multiple commands produce '.../Build/Products/Debug-iphonesimulator/MyApp.swiftmodule/arm64-apple-ios-simulator.abi.json' Target 'MyApp' (project 'MyApp') has copy command from '.../Build/Intermediates.noindex/MyApp.build/Debug-iphonesimulator/MyApp.build/Objects-normal/arm64/MyApp.abi.json' to '.../Build/Products/Debug-iphonesimulator/MyApp.swiftmodule/arm64-apple-ios-simulator.abi.json' Target 'MyAppWidgetsExtension' (project 'MyApp') has copy command from '.../Build/Intermediates.noindex/MyApp.build/Debug-iphonesimulator/MyAppWidgetsExtension.build/Objects-normal/arm64/MyApp.abi.json' to '.../Build/Products/Debug-iphonesimulator/MyApp.swiftmodule/arm64-apple-ios-simulator.abi.json' = .swiftdoc Multiple commands produce '.../Build/Products/Debug-iphonesimulator/MyApp.swiftmodule/arm64-apple-ios-simulator.swiftdoc' Target 'MyApp' (project 'MyApp') has copy command from '.../Build/Intermediates.noindex/MyApp.build/Debug-iphonesimulator/MyApp.build/Objects-normal/arm64/MyApp.swiftdoc' to '.../Build/Products/Debug-iphonesimulator/MyApp.swiftmodule/arm64-apple-ios-simulator.swiftdoc' Target 'MyAppWidgetsExtension' (project 'MyApp') has copy command from '.../Build/Intermediates.noindex/MyApp.build/Debug-iphonesimulator/MyAppWidgetsExtension.build/Objects-normal/arm64/MyApp.swiftdoc' to '.../Build/Products/Debug-iphonesimulator/MyApp.swiftmodule/arm64-apple-ios-simulator.swiftdoc' = .swiftmodule Multiple commands produce '.../Build/Products/Debug-iphonesimulator/MyApp.swiftmodule/arm64-apple-ios-simulator.swiftmodule' Target 'MyApp' (project 'MyApp') has copy command from '.../Build/Intermediates.noindex/MyApp.build/Debug-iphonesimulator/MyApp.build/Objects-normal/arm64/MyApp.swiftmodule' to '.../Build/Products/Debug-iphonesimulator/MyApp.swiftmodule/arm64-apple-ios-simulator.swiftmodule' Target 'MyAppWidgetsExtension' (project 'MyApp') has copy command from '.../Build/Intermediates.noindex/MyApp.build/Debug-iphonesimulator/MyAppWidgetsExtension.build/Objects-normal/arm64/MyApp.swiftmodule' to '.../Build/Products/Debug-iphonesimulator/MyApp.swiftmodule/arm64-apple-ios-simulator.swiftmodule'
3
1
2.3k
Oct ’23
Xcode 15 + iOS 17 adds extra padding to widgets
Xcode 15 and iOS 17 now adds extra padding to widget content, which is inconsistent with iOS 16. Run on iOS 16: Same code run on iOS 17, with extra paddings: struct WidgetView : View { var entry: Provider.Entry var body: some View { LicenseView(entry: entry) .background(Color("WidgetBackground")) .modifier { if #available(iOS 17.0, *) { $0.containerBackground(for: .widget) { Color.white // to highlight the padding on iOS 17 } } else { $0 } } } }
4
5
5.4k
Jul ’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
5k
Oct ’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
2.1k
Sep ’23
Using the same widget extension for both iOS and WatchOS
Isn't it possible to use the same widgetkit extension for both iOS and WatchOS? In the WWDC's BackyarBirds project from Apple, I can see the widget extension is added to both the multiplatform (including iOS) and the watch targets. I can also see that the SwiftUI code even uses macros to check which platform the code is running on. However, I'm having several issues with adding the same extension to both targets. When I add it to the watch target, I get a build error that I'm trying to embed an application that also builds for iOS and that is not allowed for the watch app. Not sure if any code here is helpful, but this is my widget UI code: struct AkvaWidget: Widget { private let kind = "Akva Widget" var families: [WidgetFamily] { #if os(iOS) return [.accessoryCircular, .accessoryRectangular, .systemSmall] #elseif os(watchOS) return [.accessoryCircular, .accessoryRectangular, .accessoryInline, .accessoryCorner] #endif } var body: some WidgetConfiguration { StaticConfiguration( kind: kind, provider: AkvaSnapshotTimelineProvider() ) { entry in AkvaWidgetView(entry: entry) } .configurationDisplayName("Akva") .description("Keep track of your water intake.") .supportedFamilies(families) } }
1
0
1.2k
Jul ’23
AppIntentsPackage protocol with SPM package not working
Hi, I am trying to integrate the new AppIntentsPackage protocol into my application. Especially what I want to do is to create a dedicate SPM package which holds all my app intents and then share that with my widget extension for Widget intents as well as the main iOS app for powering an AppShortcutProvider. Unfortunately I run into an issue here. I have the following explanatory setup: SPM package called ProjectAppIntents iOS target My AppIntents SPM package //Package: ProjectAppIntents public struct TestAppIntent: AppIntent { public static var title: LocalizedStringResource = "TestAppIntent" @Parameter(title: "Parameter1", optionsProvider: ParameterOptionProvider()) public var parameter: String public init(parameter: String) { self.parameter = parameter } public init() { } public func perform() async throws -> some IntentResult & ReturnsValue { .result(value: 5) } } struct ParameterOptionProvider: DynamicOptionsProvider { func results() async throws -> [String] { return ["Hello", "World"] } } public struct ProjectAppIntentsPackage: AppIntentsPackage { } My iOS app // Target: iOS import ProjectAppIntents struct ProjectApp: App { var body: some Scene { WindowGroup { ContentView() } } } extension ProjectApp: AppIntentsPackage { static var includedPackages: [AppIntentsPackage.Type] = [ ProjectAppIntentsPackage.self ] } struct ProjectShortcuts: AppShortcutsProvider { static var appShortcuts: [AppShortcut] { AppShortcut( intent: TestAppIntent(), phrases: ["Start a \(.applicationName)"], shortTitle: "Hello World", systemImageName: "house" ) } } When I now try to compile my app, I get the following build error: 2023-06-25 09:53:47.853 appintentsnltrainingprocessor[44848:2059163] Parsing options for appintentsnltrainingprocessor 2023-06-25 09:53:47.854 appintentsnltrainingprocessor[44848:2059163] Starting AppIntents SSU YAML Generation 2023-06-25 09:53:47.868 appintentsnltrainingprocessor[44848:2059163] error: The action TestAppIntent referenced in App Shortcut does not exist Command AppIntentsSSUTraining failed with a nonzero exit code So for me it seems like the compiler cannot find the AppIntent defined in an SPM package. Am I doing something wrong here or does the AppIntentsPackage protocol not work with SPM packages ? Thanks a lot for helping !
11
3
2.8k
Oct ’23
Migrating to WidgetKit, issues with editing Watch Faces on iPhone
Anyone who has successfully migrated to using WidgetKit for their Apple Watch complications, your help would be greatly appreciated! I've migrated to WidgetKit for my Watch app. On the Apple Watch Face Editor, the new Widget names and options appear correctly. However, on the iPhone Apple Watch app, it offers both WidgetKit and old ClockKit complications... this should not be. I also have found rendering issues where Watch Faces on the main My Watch tab have blank gaps for WidgetKit complications, when selecting the Watch Face they then render (see photos) I've put in a feedback FB12460375 Have tried a full clear and reinstall of my app on both devices, no change. This issue occurs on WatchOS 9.5.2 / iOS 16.5.1 and WatchOS 10 Beta 2 / iOS 17 Beta 2 Any other ideas?
5
0
1k
Jun ’24
Xcode 15 beta 2: Failed to install iOS app with widget extension to simulator or device, because widget extension is does not define either an NSExtensionMainStoryboard or NSExtensionPrincipalClass key with a string value in the NSExtension dictionar
Xcode: Version 15.0 beta 2 (15A5161b) iPhone: iOS 17.0 (21A5268h) Run from Xcode to Simulator or my iPhone, build successfully, install failed with the same error: My widget extension target info.plist file looks like the image below, and it worked find with all the previous Xcode version. After adding the key NSExtensionPrincipalClass like this: I can install my app to simaltor and my device, however, when archive and upload to the App Store (for TestFlight testing), i got another error (the first one is related to this issue, the second i could not figure out what it is):
3
1
1.5k
May ’24
ForEach in Widget: How to fit only the number of items that can be fully visible?
Hello, I have this widget: And as you can see down at the bottom, next item is very barely visible. This is because on different devices (combined with varied text sizes + number of lines) the vertical space differs quite a lot. In the past I had the limit set to 4 items in the bottom part but that often left empty space at the bottom or even overflowed still on iPhone SE. What is the proper way to tell ForEach (or any other component) to "layout as many items as can fully fit, but no more". The only solution I could think of is to use ViewThatFits and try first rendering 6 items, then 5 and so on to find the count that fully fits. But that seems maybe too complicated? Thanks.
4
2
1.1k
Oct ’23
macOS widget preview error
Following article Creating a widget extension on developer.apple.com (https://developer.apple.com/documentation/widgetkit/creating-a-widget-extension) I encountered a problem with XCode preview: it shows an error with message | RemoteHumanReadableError: Failed to launch agent | No plugin is registered to launch the process type widgetExtension. Can someone help me? macOS 13.4 XCode 14.3.1
5
0
1.7k
Mar ’24
How to use AccessoryWidgetBackground with containerBackground API on iOS 17
I have an accessoryCircular Lock Screen widget built for iOS 16: ZStack { AccessoryWidgetBackground() VStack { Text("MON") .font(.caption) Text("6") .font(.title) } } When run on iOS 17 it renders an error “Please adopt containerBackground API”. So I changed it to: VStack { Text("MON") .font(.caption) Text("6") .font(.title) } .containerBackground(for: .widget) { AccessoryWidgetBackground() } This causes the error to go away but the circular background is no longer visible (tested with iPadOS 17b2). What’s the right way to implement this?
2
1
1.7k
Sep ’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.2k
Oct ’23
WidgetKit Widgets not showing up on iOS 17
Hi, I have a set of Widgets that have worked flawlessly on Xcode 14 and iOS 16, both on Simulator and Device. With Xcode 15 beta (4), these widgets simply don't show up anymore on the iOS 17 Simulator, and I feel like I've tried everything. Then again, building with the new Xcode 15 beta on any iOS 16 or 15 simulator works fine and the widgets are available. They're just gone on iOS 17.0. When I add a new widget extension however it shows up immediately on the iOS 17 simulator. I've compared every single line on the Build Settings and couldn't find any difference there. I have also updated the SiriKit Intent to an AppIntent with no success. Anyone experiencing the same issue? Or any clue on what I could have missed?
1
3
1.3k
Jul ’23
Widget showsWidgetContainerBackground fallback
To bring my widgets to iPad lock screen, i need to detect my widget that has a background to display different contents, watch the wwdc 23 video it tells we can use .showsWidgetContainerBackground environment to apply that goal, but the problem is this code wouldn't compile because .showsWidgetContainerBackground only available in iOS 17 @available(iOS 14.0, *) struct MyWidgetView: View { @Environment(\.showsWidgetContainerBackground) var showsBackground var body: some View { ... } } So, my solution is use a environment wrapper, like this: @available(iOS 17.0, *) struct EnvironmentWrapper: View { @Environment(\.showsWidgetContainerBackground) var showsWidgetContainerBackground var body: some View { VStack(alignment: .leading) { Text("Wrapper Has Background: \(showsWidgetContainerBackground ? "YES" : "NO")") } } } extension View { var showsWidgetContainerBackground: Bool { if #available(iOS 17.0, *) { return EnvironmentWrapper().showsWidgetContainerBackground } else { return true } } } But it didn't work, this is the example: @available(iOS 17.0, *) struct EnvironmentWrapper: View { @Environment(\.showsWidgetContainerBackground) var showsWidgetContainerBackground var body: some View { VStack(alignment: .leading) { Text("Wrapper has background: \(showsWidgetContainerBackground ? "YES" : "NO")") } } } @available(iOS 17.0, *) struct ExampleView: View { @Environment(\.showsWidgetContainerBackground) var showsBackground var body: some View { VStack(alignment: .leading) { Text("Read from self: \(showsBackground ? "YES" : "NO")") EnvironmentWrapper() Text("Read from wrapper: \(EnvironmentWrapper().showsWidgetContainerBackground ? "YES" : "NO")") } .font(.system(size: 12, weight: .medium)) } } As you can see, if i read it directly from self, it works, but if i read from outside, it always return true i also try to load a view first in the wrapper, but it didn't work either func getShowsBackground() -> Bool { let _ = body return showsWidgetContainerBackground }
8
2
2.0k
Sep ’23