iOS Development

ios – LockScreen Widget reload each minute

I am presently creating a world clock LockScreen widget, which is meant to show present time of the chosen metropolis.

The code I am utilizing to reload it each minute is the next:

func getTimeline(for configuration: ConfigurationIntent, in context: Context, completion: @escaping (Timeline<ThemeEntry>) -> ()) {

        var entries: [ThemeEntry] = []

        // Generate a timeline consisting of 5 entries an hour aside, ranging from the present date.
        let currentDate = Date()
        for hourOffset in 0 ..< 60 {
            let entryDate = .hour, worth: hourOffset, to: currentDate)!
            let entry = ThemeEntry(date: entryDate, configuration: configuration, theme: ThemeEntity(index: hourOffset))

        let timeline = Timeline(entries: entries, coverage: .atEnd)

It really works as anticipated, that means 0..<60 does it is job and reloads my widget each minute, however the issue is sooner or later (after a few hours) it stops reloading and freezes.
I’ve discovered a few apps on AppStore which have the identical performance and their widgets with world time work like allure, so I suppose it is attainable to attain.

What could possibly be the answer?


Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button