Display Remote Image in a Live Activity

I have a use-case where I want to display a remote image in a Live Activity. The image can only be downloaded when the user starts the activity.

I wonder if there is a recommended way to do this. I tried using AsyncImage in the widget view, but I assume it's not working because of the network connectivity limitation of Live Activities. I also tried downloading the image beforehand in the main app and passing it as a parameter of my ActivityAttributes, however requesting the Activity results in a nondescript error: Error Domain=com.apple.ActivityKit.ActivityInput Code=1 "(null)".

The only other way to achieve this I could think of is using app groups and storing the image on disk for the widget extension to load it again, which seems unnecessarily error-prone.

I haven't tried this last approach yet, because I wanted to gather some feedback first. I'm happy about any tips and pointers you might have!

Answered by iMoritz in 733021022

I asked the question during the Ask Apple Live Activity session and got the confirmation that using App Groups and sharing the files by storing them in the group's container is the expected solution.

What I've noticed is that if the size of the data in ActivityAttributes exceeds 4K I receive this error. The docs state that the size of ContentState updates cannot exceed 4K but I haven't seen anything about limitations for the initial ActivityAttributes sent when starting an Activity. I'm not sure if this is intended behavior or just a bug in the beta? Since the Live Activity cannot perform network operations in its "sandbox" it seems very odd that you're only able to send a very small amount of data when starting an Activity.

Accepted Answer

I asked the question during the Ask Apple Live Activity session and got the confirmation that using App Groups and sharing the files by storing them in the group's container is the expected solution.

Display Remote Image in a Live Activity
 
 
Q