Darren Jones Profile picture
Sep 27, 2020 11 tweets 3 min read Read on X
A few things I’ve learnt about widgets whilst trying to add live bus times (a thread):
How often can a widget make a URLRequest to refresh its data? #iosdev 1/11
Fetching data then setting 1 solo view in the timeline and asking for a refresh in 2 minutes, will not fire for approx 5 minutes.
So 5 minutes then?
Well no. 2/11
If you add say 18 views to the timeline 10 seconds apart (3 mins) and request an update after 2 minutes, you will likely get a hit every 2 minutes and be able to call your URLRequest. 3/11
2 minutes is an ok refresh time for me displaying when the next bus is due. 5 minutes wouldn’t be as a lot can change in 5 minutes.
How do you make a widget look like it’s updated even though it hasn’t? 4/11
Well if I know the times the next few buses are due, I can use the 10 second timeline entries to show an updated ‘Due in xx’ time. A problem I faced is that all 18 timeline views are generated at the same time! 5/11
So if you use Date() in your calculations your views will all have the same data. So you have to your use date variable from your timeline entry when calculating times. With this my widget looks like it’s showing live data and the due times update in real time. 6/11
Can’t you just use the new Date() formatters for widgets?
Yes and these work great. Add a date to a widget and the clock can run up or down in real time. I use this for my ‘Last updated:’ label. The problem I had with this is you cannot use a custom format on the display. 7/11
It’s all (HH:mm:ss) or nothing.I don’t want to display seconds to the user as the live bus data is all set to 00 seconds so only accurate to the minute. Showing a user their bus is 15 seconds away will likely make them take it as gospel and think it’s accurate to the second. 8/11
So I had to use basic labels and update every 10 seconds.
One final thing I haven’t implemented yet, the refresh times may not happen when you expect. You can mostly get 2 minute updates but I’ve seen times of 15 minutes with no update with no known reason why. 9/11
I plan to add a view after 3 minutes, once I have no timeline entries left, telling the user to tap to open the app. You can force refresh your widget from within the app as often as you like, so I fire a refresh when the main app goes into the background. 10/11
I’m very happy with the result and once a bus’s due time was over a minute ago it’s removed from the stack and the next one shown, even if I haven’t been able to get a URLRequest with new data. 11/11

• • •

Missing some Tweet in this thread? You can try to force a refresh
 

Keep Current with Darren Jones

Darren Jones Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Don't want to be a Premium member but still want to support us?

Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal

Or Donate anonymously using crypto!

Ethereum

0xfe58350B80634f60Fa6Dc149a72b4DFbc17D341E copy

Bitcoin

3ATGMxNzCUFzxpMCHL5sWSt4DVtS8UqXpi copy

Thank you for your support!

Follow Us!

:(