TEAM LICENSES: Save money and learn new skills through a Hacking with Swift+ team license >>

Lock Screen Widget (.accessoryCircular) does not refresh

Forums > Swift

Hi, I'm having the following issue: I'm building an app that has a widget on the lockscreen. The widget displays the elapsed time of a stopwatch. I am reloading the timeline manually each time the app becomes inactive. But it does not reload always. If I swipe to reveal Notifcation Center, although the app becomes inactive, widget will not update.

Although reloadTimeline is called each time, getTimeline(...) function of the TimelineProvider does not get called

I need to put the app in the background first and then it will refresh. Is this a bug in the framework?

Thanks guys in advance for your answers! Below is the code

        NotificationCenter.default.addObserver(forName: UIApplication.willResignActiveNotification, object: nil, queue: nil) { _ in
            WidgetCenter.shared.reloadAllTimelines()
        }
func getTimeline(for configuration: ConfigurationIntent, in context: Context, completion: @escaping (Timeline<Entry>) -> ()) {
        print(#function)

        dataFetcher.fetch { bubbleData in
            var entries = [Entry]()

            let currentClock = TimeInterval(bubbleData.isTimer ? bubbleData.value : -bubbleData.value)

            let input = Entry.Input(isRunning: bubbleData.isRunning, startValue: currentClock, isTimer: bubbleData.isTimer)
            let entry = Entry(date: Date(), configuration: ConfigurationIntent(), input: input)

            entries.append(entry)

            let timeline = Timeline(entries: entries, policy: .never)
            completion(timeline)
        }
    }

2      

Hacking with Swift is sponsored by Blaze.

SPONSORED Still waiting on your CI build? Speed it up ~3x with Blaze - change one line, pay less, keep your existing GitHub workflows. First 25 HWS readers to use code HACKING at checkout get 50% off the first year. Try it now for free!

Reserve your spot now

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.