Last active
June 28, 2023 22:51
-
-
Save tarrouye/517ef7587abc6668da42620203adf995 to your computer and use it in GitHub Desktop.
Present SFSafariViewController as a NavigationController from SwiftUI.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// UIApplication+Safari.swift | |
// DoraDora | |
// | |
// Created by Théo Arrouye on 5/12/23. | |
// | |
import SafariServices | |
import UIKit | |
extension UIApplication { | |
var firstKeyWindow: UIWindow? { | |
return UIApplication.shared.connectedScenes | |
.compactMap { $0 as? UIWindowScene } | |
.filter { $0.activationState == .foregroundActive } | |
.first?.keyWindow | |
} | |
func showSafariView(url: URL?) { | |
guard let url else { return } | |
let vc = SFSafariViewController(url: url) | |
firstKeyWindow?.rootViewController?.present(vc, animated: true) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Use it in your views like so:
Using this method avoids weird issues with double navigation bars, etc.