I'm trying to watch youtube videos in my app's UIWebView itself. Whenever I tap on any of the webpage youtube link, it will automatically redirect into youtube application but youtube's app is also installed in my device. How can I block opening of one app from another app programmatically.
Asked
Active
Viewed 868 times
2
-
1did u implement the web view delegate methods ? You can return NO, when the UIWebViewNavigationType is a UIWebViewNavigationTypeLinkClicked. – Teja Nandamuri Aug 03 '18 at 15:50
-
https://stackoverflow.com/a/37240425/5622566 have you tried this? – Kamaldeep singh Bhatia Aug 08 '18 at 12:14
1 Answers
4
If you are using UIWebview
Add following delegate method in your viewcontroller. And assign webview.delegate = self
extension YourVC:UIWebViewDelegate{
func webView(_ webView: UIWebView, shouldStartLoadWith request: URLRequest, navigationType: UIWebViewNavigationType) -> Bool {
if navigationType == UIWebViewNavigationType.linkClicked {
return false
}
return true
}
}
If you are using WKWebview
,
Add following delegate method in your viewcontroller. And assign webView.navigationDelegate = self
extension YourVC:WKNavigationDelegate{
func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) {
if navigationAction.navigationType == .linkActivated {
decisionHandler(.cancel);
return;
}
decisionHandler(.allow);
}
}

Mehul Thakkar
- 12,440
- 10
- 52
- 81