From 03fdce358d4eab8e0a4a81b6e738a0b4699ecde0 Mon Sep 17 00:00:00 2001 From: Daniil Vinogradov Date: Sat, 13 Jul 2024 13:50:39 +0200 Subject: [PATCH] Fix crash on incompatible URL for Safari ViewController --- .../Rss/Details/RssDetailsViewController.swift | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/iTorrent/Screens/Rss/Details/RssDetailsViewController.swift b/iTorrent/Screens/Rss/Details/RssDetailsViewController.swift index b6a88c48..896f05ae 100644 --- a/iTorrent/Screens/Rss/Details/RssDetailsViewController.swift +++ b/iTorrent/Screens/Rss/Details/RssDetailsViewController.swift @@ -14,11 +14,13 @@ class RssDetailsViewController: BaseViewController var webView: WKWebView! override func loadView() { - let button = UIBarButtonItem(primaryAction: .init(image: .init(systemName: "safari"), handler: { [unowned self] _ in - let safariVC = BaseSafariViewController(url: viewModel.rssModel.link) - present(safariVC, animated: true) - })) - navigationItem.setRightBarButton(button, animated: false) + if UIApplication.shared.canOpenURL(viewModel.rssModel.link) { + let button = UIBarButtonItem(primaryAction: .init(image: .init(systemName: "safari"), handler: { [unowned self] _ in + let safariVC = BaseSafariViewController(url: viewModel.rssModel.link) + present(safariVC, animated: true) + })) + navigationItem.setRightBarButton(button, animated: false) + } webView = WKWebView() webView.backgroundColor = .secondarySystemBackground