WidgetKit's TimelineProvider maximum processing time

I am developing an iOS Home Screen widget for our app. The widget renders an image retrieved from the user's photo library in each of its timeline entries. Sometimes in the TimelineProvider.getTimeline(...) method execution stops while accessing the PHAssets.

Retrieving the PHAssets from the photo library takes around 700-800ms. Adding logs the method reveals that execution just stops. The timeline's completion handler never gets called.

Suspension of the method only happens while not debugging the method.

I wonder if there is some kind of limit on how long getTimeline is allowed to execute or on how much data the process is allowed to haul around.

Thanks in advance for any information you can provide.

Replies

Thanks for the question, there's a limit depending on the device condition, but I don't think 700-800ms is anywhere close to that.

Have you tried putting a Task.sleep function call inside the timeline generation method to force delaying the timeline generation by 1-2 seconds (or a time slightly longer than your usual code) to see if it times out?

Keep in mind there's also a memory limit for your WidgetKit process, so I would also try testing with PHAssets of different sizes and see if that makes a difference.

Thank you for your answer. Possibly, this issue is a symptom of the behaviour described in a followup post: https://developer.apple.com/forums/thread/730134. I get back to you as soon as we have resolved the other issue and can validate that the issue described in this post is unrelated.