2

I realized you can display images in widget like this stack overflow answer. https://stackoverflow.com/a/64163384/13476728

However, I was wondering if this keeps calling the url every time when it refreshes through timelineprovider? if it does, how do i store the image through cache and display it so it doesnt call the url every time. (In this example "https://www.test.com")

Group {
        let tempUrl = URL(string: "https://www.test.com")!
           if let url = tempUrl, let imageData = try? Data(contentsOf: tempUrl),
              
                
             let uiImage = UIImage(data: imageData) {
             if(uiImage != nil){
             Image(uiImage: uiImage)
               .resizable()
             } else{
               black
             }
            }
                      }
James Lee
  • 656
  • 1
  • 7
  • 22
  • 1
    If you look t the Widget Code along from apple, their sample project uses local files. You might be able to get some implementation ideas from that. In the project files themselves not necessarily the tutorial. – lorem ipsum Aug 03 '22 at 22:25
  • 1
    Look at `URLCache` – Asperi Aug 04 '22 at 03:53

0 Answers0