Questions tagged [widgetkit]

Use for WidgetKit introduced in iOS 14 and macOS Catalyst 14

Docs: https://developer.apple.com/documentation/widgetkit

520 questions
8
votes
1 answer

How to get the size of the corner radius of widget in SwiftUI?

I want to maintain the same inset around my custom view. Exterior corner radius is required to change the corner radius of our custom views, I could not find any environment variable or any other way to get the corner radius of the widget…
YodagamaHeshan
  • 4,996
  • 2
  • 26
  • 36
8
votes
1 answer

In WidgetKit with dynamic data, how to specify the default IntentConfiguration for new widgets?

The desirable example is exhibited by the Apple Notes widgets. When adding an Apple Notes widget, WidgetKit goes ahead and assigns an IntentConfiguration to the new widget. You can see this by editing the widget and noticing that the selection…
AVS
  • 373
  • 3
  • 19
8
votes
1 answer

How to refresh Widget when Main App is used?

I am using an UIKit app and added a widget with SwiftUI and Widgetkit. Now I want to update the widget when the user does something one the main app. Normally I should use WidgetCenter.shared.reloadAllTimelines() right? But this only works with…
submariner
  • 308
  • 1
  • 5
  • 23
8
votes
2 answers

How to read files created by the app by iOS WidgetKit?

I am developing an app with widgetKit extension, and I want to show data created by the user on the widget. How can the widgetKit read files created by the app?
Collin Zhang
  • 483
  • 5
  • 14
8
votes
2 answers

WidgetBundle return widgets based on some logic

I have several iOS14 Home screen Widgets ready for my app and return them all in WidgetBundle like this: @main struct WidgetsBudle: WidgetBundle { @WidgetBundleBuilder var body: some Widget { Widget1() Widget2() …
sabius
  • 704
  • 7
  • 10
8
votes
3 answers

WidgetCenter not found in scope

I'm building an iOS app for iOS 10+. The app builds fine in Debug configuration, but in Release fails to compile swift source code that references WidgetCenter. It outputs the error Cannot find WidgetCenter in scope even though I'm importing…
Taylor Johnson
  • 1,845
  • 1
  • 18
  • 31
8
votes
1 answer

Widget not getting updated even when UserDefaults are synchronized

I am using XCode 12 beta 2 (iOS 14 Sim) to pass data from my app to the widget using AppContainer. I am using the below code to save data (here String) to app container. let userDefaults = UserDefaults(suiteName: "group.abc.WidgetDemo") …
Abhishek Bedi
  • 5,205
  • 2
  • 36
  • 62
7
votes
1 answer

How can we add a Lock Screen Widget (requiring iOS 16) and still support iOS 15?

How can we add a Lock Screen Widget to an existing Widget Bundle and still support iOS 15? :thinking_face: for ex this won't compile struct SecondExtraBundle: WidgetBundle { @WidgetBundleBuilder var body: some Widget { …
GarySabo
  • 5,806
  • 5
  • 49
  • 124
7
votes
2 answers

Right-aligning Text(Date(), style: .timer) text in an iOS WidgetKit widget

Here's an interesting quandary: I want to make a timer that "ticks" reliably but, also, renders symbols in predictable places so that I could, for instance, decorate the timer by adding a background. Because of WidgetKit limitations, I cannot…
Baglan
  • 1,057
  • 10
  • 23
7
votes
4 answers

SwiftUI widget not updating when @AppStorage value is changed

I am trying to get a SwiftUI widget to update on command when the value of the @AppStorage changes. When I load the simulator the widget updates to the correct value from @AppStorage but does not update again no matter what I try. To display a new…
Jon T
  • 71
  • 1
  • 4
7
votes
1 answer

How can I keep the existing entry on WidgetKit refresh?

I'm using HealthKit data in my widget. If the phone is locked, it's not possible to get HealthKit data, only if the phone is unlocked. However, my widget timeline's will try to update even if the phone is locked. Is it possible to return an empty…
passatgt
  • 4,234
  • 4
  • 40
  • 54
7
votes
0 answers

How do I fetch HomeKit values for usage in iOS 14 Widgets?

I am writing a HomeKit app that successfully shows live data from my supported accessories in-app. I can read single values (HMCharacteristic.readValue) or use notifications to stay updated (HMCharacteristic.enableNotification). Now I want to…
theMomax
  • 919
  • 7
  • 8
7
votes
2 answers

SwiftUI Widget iOS 14 gradient issue

I want to create a gradient color for my widget using custom colors. And I have a problem when I only use two colors, as a result, not one of the colors is applied, but the background turns green! struct WeatherWidgetMediumView: View { var…
Maxim Zakopaylov
  • 546
  • 2
  • 5
  • 23
7
votes
3 answers

'main()' is only available in application extensions for iOS 14.0 or newer

I added widget target in my app, and I tried to the iOS 14 and newer condition for that, but I still got this error: 'main()' is only available in application extensions for iOS 14.0 or newer @available(iOSApplicationExtension 14.0,…
Robert kont
  • 165
  • 1
  • 8
7
votes
1 answer

WidgetPreviewContext is not working in a framework

I made a widget using new and shiny WidgetKit. It looks good and working as expected. Then I put all its logic into separate framework to share constant values between extension and main app as well as to provide a unit-testable target. And after…
Artem Kirillov
  • 1,132
  • 10
  • 25
1 2
3
34 35