widgetkit

Setting the TimelineProvider refresh interval for Widget

天大地大妈咪最大 提交于 2021-01-15 19:01:03
问题 Right now my Widget makes about 1 request per second. I want to change it to 1 request in 1 hour. I get some errors on the line with let timeline = ... like Value of optional type 'Date?' must be unwrapped to a value of type 'Date' and some more. Any suggestions what could be wrong: struct Provider: IntentTimelineProvider { let networkManager = NetworkManager() func placeholder(in context: Context) -> SimpleEntry { SimpleEntry(date: Date(), configuration: ConfigurationIntent(), clubname:

Setting the TimelineProvider refresh interval for Widget

五迷三道 提交于 2021-01-15 18:56:53
问题 Right now my Widget makes about 1 request per second. I want to change it to 1 request in 1 hour. I get some errors on the line with let timeline = ... like Value of optional type 'Date?' must be unwrapped to a value of type 'Date' and some more. Any suggestions what could be wrong: struct Provider: IntentTimelineProvider { let networkManager = NetworkManager() func placeholder(in context: Context) -> SimpleEntry { SimpleEntry(date: Date(), configuration: ConfigurationIntent(), clubname:

How to pass uiviewcontroller data to swiftui widget class

萝らか妹 提交于 2021-01-07 01:36:12
问题 How to pass uiviewcontroller data to swiftui widget class i am unable to do it with app groups also write now i am sending it with userdefaults but unable to do it if let userDefaults = UserDefaults(suiteName: "group.com.soup.ios.app") { UserDefaults.standard.set(self.dat ?? "", forKey: "date") UserDefaults.standard.set(self.textData.text ?? "", forKey: "text") } if let userDefaults = UserDefaults(suiteName: "group.com.soup.ios.app") { let text = UserDefaults.standard.object(forKey: "text")

SwiftUI Widget background based on the value passed image url or gradient background

北城余情 提交于 2021-01-05 07:38:27
问题 What I would like to do is give the user the option to choose whether the widget background is an image taken from http or a gradient background . I currently have the following note structure, but I can't get it to work. So typeBg must have a default value, if not passed it should take the default value. The values of image and bgColors must be optional parameters. struct Note: Identifiable, Codable { let title: String let message: String let image: String? let bgColors: [Color?]//[String?]

Can I add WidgetKit extensions to an app with target iOS < 14?

前提是你 提交于 2021-01-02 05:48:30
问题 I want to add a (WidgetKit-)widget to my iOS app. The app itself should keep a target of < 14. Obviously, the widget would be available only on those devices >= 14, but the app should run on all other devices as well. Is this possible? 回答1: Yes, you can as I develop the Widgets on an iOS13 Xcode project. You can see them on an iPhone that runs iOS14 and not on the iOS13 one. You just need to add @available(iOS14) in your code because you are using WidgetKit. But don't worry, Xcode will remind

Can I add WidgetKit extensions to an app with target iOS < 14?

邮差的信 提交于 2021-01-02 05:46:16
问题 I want to add a (WidgetKit-)widget to my iOS app. The app itself should keep a target of < 14. Obviously, the widget would be available only on those devices >= 14, but the app should run on all other devices as well. Is this possible? 回答1: Yes, you can as I develop the Widgets on an iOS13 Xcode project. You can see them on an iPhone that runs iOS14 and not on the iOS13 one. You just need to add @available(iOS14) in your code because you are using WidgetKit. But don't worry, Xcode will remind

Sharing Data with AppGroup

北战南征 提交于 2020-12-26 09:06:16
问题 I want to share one variable from my UIKit File to my Widget Extension created with SwiftUI. I followed this here. Please look at the answer from J Arango. But i dont understand the last part there. I have to use import MySharedObjects . So I did this: import MySharedObject struct testing { let mySharedObject = MySharedObject(name: "My Name", lastName: "My Last Name") do { let data = try JSONEncoder().encode(mySharedObject) /// Make sure to use your "App Group" container suite name when

How to display Current Time (Realtime) in iOS 14 Home Widget

橙三吉。 提交于 2020-12-26 08:45:48
问题 I am developing an application for ios 14 Home Widget and I am facing a problem while showing the current time (digital clock) that the widget not getting updated every sec. As we all know, Apple does not allow to trigger timeline every second is there any other way to display the current time with the realtime updates? I tried these methods but not works as expected class NetworkManager: ObservableObject { @Published var dateIs = Date() init() { startTimer() // fetch data must be called at

How to display Current Time (Realtime) in iOS 14 Home Widget

被刻印的时光 ゝ 提交于 2020-12-26 08:43:31
问题 I am developing an application for ios 14 Home Widget and I am facing a problem while showing the current time (digital clock) that the widget not getting updated every sec. As we all know, Apple does not allow to trigger timeline every second is there any other way to display the current time with the realtime updates? I tried these methods but not works as expected class NetworkManager: ObservableObject { @Published var dateIs = Date() init() { startTimer() // fetch data must be called at

How to update iOS 14 Widget background color from the app?

↘锁芯ラ 提交于 2020-12-26 08:34:19
问题 For my widget, I want users to be able to select a widget background color of their choice, but I can't seem to get it to work. I'm trying to do this with a ColorPicker and @AppStorage ColorPicker("Background Color", selection: Binding(get: { bgColor }, set: { newValue in backgroundColor = self.updateColorInAppStorage(color: newValue) bgColor = newValue })) .frame(width: 200, height: 50) .font(.headline) backgroundColor is an @AppStorage variable that holds the RGB values In my Widget