iOS WidgetKit: remote images fails to load
Yes, as mentioned by Konstantin, it is not supported to load images asynchronously. There are 2 options to load network image in widgets
Either fetch all the images in TimelineProvider and inject them to the views directly.
OR
Use
Data(contentsOf: url)
to fetch the image. This way it still fetches them synchronously but the code is cleaner. Sample code -struct NetworkImage: View { private let url: URL? var body: some View { Group { if let url = url, let imageData = try? Data(contentsOf: url), let uiImage = UIImage(data: imageData) { Image(uiImage: uiImage) .resizable() .aspectRatio(contentMode: .fill) } else { Image("placeholder-image") } } } }
This view can simply be use like this -
NetworkImage(url: url)
Got it: it's simply not supported and you aim to load images inside TimelineProvider:
https://developer.apple.com/forums/thread/652581