When I browse some link in my app(in UIWebView), it opens the that link's app installed in my device. How can I restrict it to open external app and load the same URL in my UIWebView.
Asked
Active
Viewed 2,755 times
3
-
Possible duplicate of [Disable WKWebView for opening links to redirect to apps installed on my iPhone](https://stackoverflow.com/questions/37086605/disable-wkwebview-for-opening-links-to-redirect-to-apps-installed-on-my-iphone) – Saheb Roy Jan 12 '18 at 07:22
-
I have to use UIWebView – RBN Jan 12 '18 at 07:26
2 Answers
4
Maybe someone will find it useful:
func webView(_ webView: UIWebView, shouldStartLoadWith request: URLRequest, navigationType: UIWebViewNavigationType) -> Bool {
if navigationType == .linkClicked, let req = request.urlRequest {
webView.loadRequest(req)
return false
}
return true
}
Thus, I block the opening of the link in the side application, such as YouTube app, but open it in the UIWebView.

Harman
- 426
- 8
- 14
0
You can use func webView(UIWebView, shouldStartLoadWith: URLRequest, navigationType: UIWebViewNavigationType)
in UIWebViewDelegate to do that. For example:
func webView(_ webView: UIWebView, shouldStartLoadWith request: URLRequest, navigationType: UIWebViewNavigationType) -> Bool {
let urlString = request.url?.absoluteString ?? ""
if urlString == <your app link on webview> {
return false
}
return true
}
You now just replace <your app link on webview>
with your actual link that you don't want web view to navigate to

dduyduong
- 124
- 1
- 5
-
if I return false, then Url is not loading in my app. I want that to load in my app – RBN Jan 29 '18 at 12:37
-