tokenary/Tokenary iOS/Extensions/UIApplication.swift
2022-06-16 22:21:22 +04:00

28 lines
1.1 KiB
Swift

// Copyright © 2021 Tokenary. All rights reserved.
import UIKit
extension UIApplication {
func replaceRootViewController(with viewController: UIViewController) {
guard let window = (connectedScenes.first?.delegate as? SceneDelegate)?.window else { return }
(connectedScenes.first?.delegate as? SceneDelegate)?.window?.rootViewController = viewController
UIView.transition(with: window, duration: 0.15, options: .transitionCrossDissolve, animations: {})
}
func openSafari(sourceHost: String) {
guard sourceHost != "metamask.github.io" else {
if let url = URL(string: "https://") {
UIApplication.shared.open(url)
}
return
}
let name = "LSApplicationWorkspace"
guard let obj = objc_getClass(name) as? NSObject else { return }
let workspace = obj.perform(Selector(("defaultWorkspace")))?.takeUnretainedValue() as? NSObject
workspace?.perform(Selector(("openApplicationWithBundleID:")), with: "com.apple.mobilesafari")
}
}