|
In my app, I need to display some HTML string content so I created a UIViewRepresentable like below:
and I display it in my view like so:
The problem is that some of the HTML content have links and they open within the view. How can I open the links in Safari Browser or at least a sheet instead? Any help will be appreciated. I am very much new ro Swiftui. Thank you. |
|
You can add this
Check out this article How to open web links in Safari |
|
|
|
|
|
Sir, I made it clear that
that is why I created "HTMLStringView" that conforms to a "UIViewRepresentable" of the type "WKWebView". I also stated clearly that my problem is:
The problem is so clear. If I want to open a link, I would use Link(). If you read thruough you will discover that my problem isn't about opening links sir. Thank you. |
|
For anyone having the same problem, here is how I was able to solve it eventually: First of all I created a URL extension to test if the URL is reachable. This part is optional. I needed it so that users are not taken away from my app if indeed the URL leads nowhere:
Then I created a Coordinator class to serve as the WKNavigationDelegate:
I added the following line to my struct to make it aware of the Coordinator:
Finally, I assign the coordinator as the view's navigation delegate
And my links within the HTML String now open inside Safari instead of in my app. |
SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's all new Paywall Editor allow you to remotely configure your paywall view without any code changes or app updates.
Sponsor Hacking with Swift and reach the world's largest Swift community!
This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.
All interactions here are governed by our code of conduct.
Link copied to your pasteboard.