AsyncImage icon indicating copy to clipboard operation
AsyncImage copied to clipboard

Image disappears after app resigns active

Open lukemorse opened this issue 4 years ago • 3 comments

Hello,

First of all, thanks for the great code! I'm experiencing an issue when the app enters background, and then becomes active again. The image goes away, replaced by the placeholder, and the image never reloads. I get this error in the console: 2020-06-30 15:53:20.517988-0500 AsyncImage[23959:3569320] [] nw_read_request_report [C1] Receive failed with error "Software caused connection abort"

Anybody find a way to fix this?

lukemorse avatar Jun 30 '20 20:06 lukemorse

Hi @lukemorse ! If I correctly understood and reproduced the issue, the problem was that onDisappear() was called when view entered background, but onAppear() was never called. Could you please check again with the current version of the project? It now uses StateObject instead of ObservedObject, which, from my experience, fixed the problem.

V8tr avatar Sep 24 '20 15:09 V8tr

@lukemorse This may not be the best way and it may expose other issues, but if your constructor looks like this:

init(url: URL) {
    self.url = url
  }

You can change it to this and images now show when coming back in iOS13

init(url: URL) {
    self.url = url
    
    load()
  }

nthState avatar Jan 15 '21 23:01 nthState

I'm experiencing this issue too, however not when backgrounding. It seems that onAppear is not called when the bound image url changes either.

In my case when my view loads, an AsyncImage is rendered with a binding to a selectedImageURL property. The image init is called first and then onAppear is called triggering the image load, which loads the current selected image.

However when I pop up an image picker sheet and allow the user to change the selected image, which changes the selectedImageURL binding, the view is rebuilt and the init is called again, but the onAppear is not called again. This means the old selected image stays visible.

nrj avatar Aug 23 '21 10:08 nrj