Thank you, NaimadDev, for the quick reply. Got 1 step forward.
I am using struct WebView : UIViewRepresentable { } to load my html.site with WKWebView(). Within the Webview I have a Coordinator to trigger once website is fully loaded.
struct WebView : UIViewRepresentable {
...
@Binding var showLoading: Bool
func makeCoordinator() -> Coordinator {
Coordinator(didStart: {
showLoading = true
}, didFinish: {
showLoading = false
saveWebView(EmulatorView())
})
}
...
Once didFinish, I call the WebView extension function saveWebView with the EmulatorView, The EmulatorView contains my Website called with WebView(showLoading: $showLoading)
extension WebView {
@MainActor func saveWebView(_ view: EmulatorView) {
let renderer = ImageRenderer(content: view)
renderer.scale = 3.0
renderer.isOpaque = false
if let image = renderer.uiImage {
if let data = image.pngData() {
if let filedirectory = FileManager.default.url(forUbiquityContainerIdentifier: nil)?.appendingPathComponent("Documents").appendingPathComponent("\(selectedPreviewTheme)") {
if (FileManager.default.fileExists(atPath: filedirectory.path, isDirectory: nil)) {
let filepath = filedirectory.appendingPathComponent("01_Screenshot_\(selectedPreviewTheme).png")
try? data.write(to: filepath)
}
}
}
}
}
}
The EmulatorView will be rendered, BUT unfortunately just a 216x216 png with my Emulator .background(Color("background2")). If I use another view from my app, e.g. the OnboardingView(), this one will be rendered fine.
Any ideas are highly appreciated
Eric
Post
Replies
Boosts
Views
Activity
You might use symbol.Name
https://developer.apple.com/documentation/weatherkit/currentweather/symbolname
Refer to
SF Symbols --> Weather
to get icons
https://developer.apple.com/sf-symbols/
e.g. cloud.rain and more
Got it to work with task, thank you.
Structure
Task
A unit of asynchronous work.
https://developer.apple.com/documentation/swift/task
Thanks.