TEAM LICENSES: Save money and learn new skills through a Hacking with Swift+ team license >>

Possible to show snapshot of app in widget?

Forums > SwiftUI

Hi. I'm trying to make a widget to go alongside my app after watching Paul's "Spaced Out" stream. My main app functionality is around a MKMapView with overlays and annotations that are loaded from an api. Because map views cannot be added to widgets, i took to looking at MKMapSnapshotter, but that doesn't appear to have a way of adding MKOverlays. Back to the drawing board! I figured the best thing to do (to save me a lot of headaches) is to import the main app's ContentView, load the map, it's data, render the overlays, and then send back a UIImage to display in the widget context. The problem being is that the contentview seems to not be in memory for long and the callback is never hit. I've tried holding my content view in various places as either a static, or as a variable in some ObservableObject that belongs to different places, but I clearly don't understand what is going on or how this works. I did nearly give up on this as "not possible" but then saw the google maps widget with a little rendered version of it's own map, local traffic included, so I'm not sure on how they're doing it. It is about 2:30am and I've been on with this for ~3 hours now so I probably need fresh eyes, but was wondering if anyone can think of a better way to do this as I appear to be stuck down a rabbit hole.. Thanks

2      

Hacking with Swift is sponsored by String Catalog.

SPONSORED Get accurate app localizations in minutes using AI. Choose your languages & receive translations for 40+ markets!

Localize My App

Sponsor Hacking with Swift and reach the world's largest Swift community!

Reply to this topic…

You need to create an account or log in to reply.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.