Pulling my hair out with Widgets

Here's my WidgetConfigurationIntent:

WidgetEventDetails is a struct conforming to AppEntity, Identifiable, Hashable. It contains all the data needed to show in a widget.

Here's my placeholder, snapshot, timeline etc.:

When I go to add a widget to my iPhone Home Screen I choose my app, and the small and medium widgets are displayed, and they use the data from the placeholder function correctly, i.e. a random set of data (an 'event') is returned and seen in the widget picker.

I select a widget and it appears on the Home Screen, but it's now just a placeholder view, and it stays like that forever. If I hold down and edit the widget, there's no selected event, as in, I might've picked "Christmas" from the widget picker but when it gets added to the Home Screen that link is lost.

So, I edit the widget and go to choose any event, and this appears for ages:

When it finally displays the list of events I pick one and the widget looks this forever:

I can't see what I'm doing wrong. Any ideas? If you need any more of the code, please just ask. I'm getting really frustrated with this stuff and just want it to work.

I get so far with it, it all goes well, then something happens and it just breaks. And it's not my coding as I'm using git and can can go back to previous commits where stuff was working, only to find it doesn't. I'm glad iOS 17 now has this "State of Mind" logging 'cos it shows exactly how I feel developing for iOS! 🥸

Accepted Reply

More debugging... Looks like I was adding too many timeline entries.

Doesn't explain why the entire thing exhibits the behaviours seen above just because there are too many timeline entries. Surely iOS should simply not add any over a certain count or memory footprint, or at least warn the developer instead of appearing to be utterly broken?

Replies

Some debugging later...

.1. Bring up the widget picker. It shows the code picking two random events, one each for the small and medium widgets. It picked the "Gallery Opening" event for both of them.

.2. Log output shows:

snapshot: inPreview, returning random events // One for the small widget
snapshot: inPreview, returning random events // Medium widget
WidgetMedium: event.name = 'Gallery Opening' // Medium widget called to display the "Gallery Opening" event
snapshot: inPreview, returning random events // Not sure why there's a third call, but anyway...

.3. Despite having selected the medium widget that showed "Gallery Opening", the widget is added to the Home Screen without an event selected:

.4. I didn't pick the "Paris Trip" event, but the log shows the medium widget being called multiple times for that event:

timeline: event.name = Paris Trip
WidgetMedium: event.name = 'Paris Trip'
WidgetMedium: event.name = 'Paris Trip'
WidgetMedium: event.name = 'Paris Trip'
... repeated lots of times

.5. Edit the widget. No event has been chosen. I would assume this should be "Gallery Opening" since that's what I picked from the widget picker earlier. How do you link the event picked in the widget picker to the event it should display?!:

.6. From the events list, I picked "London Party", and this shows in the log:

theEvent: caller: 'timeline': looking for id = London Party!
theEvent: caller: 'timeline': event.name = 'London Party!, event.location = 'London'
timeline: event.name = London Party!
WidgetMedium: event.name = 'London Party!'
WidgetMedium: event.name = 'London Party!'
WidgetMedium: event.name = 'London Party!'
... repeated lots of times

So it is definitely calling the medium widget with the correct event that I've picked, but...

.7. Close the event picker, and the widget remains redacted and as though no event has been selected. It doesn't get updated:

I'm really at the end of my tether with this. It's not entirely obvious how this stuff is supposed to work. I've based this off the Backyard Birds example, but while it works fine there, it fails here. I just don't understand how to get this to work properly.

More debugging... Looks like I was adding too many timeline entries.

Doesn't explain why the entire thing exhibits the behaviours seen above just because there are too many timeline entries. Surely iOS should simply not add any over a certain count or memory footprint, or at least warn the developer instead of appearing to be utterly broken?