Post

Replies

Boosts

Views

Activity

Can't integrate refresh policy
In this link (Apple Developer Document) use this to update a widget: - https://developer.apple.com/documentation/widgetkit/timelineprovider // Request a timeline refresh after 2.5 hours. let date = Calendar.current.date(byAdding: .minute, value: 150, to: Date()) let timeline = Timeline(entries: entries, policy: .after(date)) completion(timeline) This is my Code right now: struct Provider: IntentTimelineProvider {     let networkManager = NetworkManager()     func placeholder(in context: Context) -> SimpleEntry {         SimpleEntry(date: Date(), configuration: ConfigurationIntent(), clubnamehome: networkManager.clubNameHome)     } func getSnapshot(for configuration: ConfigurationIntent, in context: Context, completion: @escaping (SimpleEntry) -> ()) {         let entry = SimpleEntry(date: Date(), configuration: configuration, clubnamehome: networkManager.clubNameHome)         completion(entry)     } func getTimeline(for configuration: ConfigurationIntent, in context: Context, completion: @escaping (Timeline<Entry>) -> ()) {         var entries: [SimpleEntry] = []   // Generate a timeline consisting 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: .hour, value: hourOffset, to: currentDate)!             let entry = SimpleEntry(date: entryDate, configuration: configuration, clubnamehome: networkManager.clubNameHome)             entries.append(entry)         } //wie oft geupdatet werden soll         let date = Calendar.current.date(byAdding: .minute, value: 15, to: Date())         let timeline = Timeline(entries: entries, policy: .after(date!)) completion(timeline) } } What am I doing wrong? Can someone please help me to integrate a refresh policy?
0
0
451
Oct ’20
Updating Timeline Policy on widget
Hi, my widget does a json request at the beginning. But it doesn't stop. It makes 10-20 requests per second. How can I stop that? This is the timeline of my code: struct Provider: IntentTimelineProvider {     let networkManager = NetworkManager()     func placeholder(in context: Context) -> SimpleEntry {         SimpleEntry(date: Date(), configuration: ConfigurationIntent(), clubname: networkManager.clubName)     } func getSnapshot(for configuration: ConfigurationIntent, in context: Context, completion: @escaping (SimpleEntry) -> ()) {         let entry = SimpleEntry(date: Date(), configuration: configuration, clubname: networkManager.clubName)         completion(entry)     }     func getTimeline(for configuration: ConfigurationIntent, in context: Context, completion: @escaping (Timeline<Entry>) -> ()) {         var entries: [SimpleEntry] = []       &#9;let currentDate = Date()         for hourOffset in 0 ..< 5 {             let entryDate = Calendar.current.date(byAdding: .hour, value: hourOffset, to: currentDate)!             let entry = SimpleEntry(date: entryDate, configuration: configuration, clubname: networkManager.clubName)             entries.append(entry)         }     let nextUpdate = Calendar.current.date(byAdding: .hour, value: 1, to: Date())   let timeline = Timeline(entries: entries, policy: .after(nextUpdate))         completion(timeline)     } } This is my JSON Request: class NetworkManager: ObservableObject {     @Published var posts = [Post]()     @Published var clubName = "..."     @Published var teamId = "30"     @Published var gastMannschaft = "..."     let testStr = UserDefaults(suiteName: "....")!.string(forKey: "test")     func fetchData() {         let teamId = testStr ?? "47"         if let url = URL(string: "...=" + teamId) {.             let session = URLSession(configuration: .default)             let task = session.dataTask(with: url) { (gettingInfo, response, error) in                 if error == nil {                     let decoder = JSONDecoder()                     if let safeData = gettingInfo {                         do {                             let results = try decoder.decode(Results.self, from: safeData)                             DispatchQueue.main.async {                                  self.clubName = results.data[0].away_name                                  if #available(iOS 14.0, *) {                                     WidgetCenter.shared.reloadAllTimelines()                                 } else {                                     // Fallback on earlier versions                                 }   }                         } catch { print(error) }                     }                 }             }             task.resume()         }     } }
0
0
567
Sep ’20
Conditionaly set Storyboard at start
Hello, I have two Storyboards. One is called Main the other ist called intro. When the user starts the app I want an if else statement and ask for a variable. I want somethings like: If variable is ok then show Main Storyboard else show Intro Storyboard. How can I do that? Does anyone has a code snippet easy to understand? Thank You. I read somethings about appdelegate?
0
0
421
Aug ’20
Setting variables with first start of app
Hello, i want to write an app which asks the user with the first start of the app to choose between a few options. Depending what have been chosen the app will load some data from an api. The question will never appear again. Maybe I will give the user the option to change it in the settings. As a beginner in swift I thought I could use viewdidload. But that would show the question view on every start. But thats not what I want. What do I have to google for? Can you name me the thing I search? Or do I kinda have to set a variable which is for example 0 and if the user selects an option it will get something different then 0 and that will disable the asking view with an if function?
0
0
548
Jul ’20