metatext-app-ios-iphone-ipad/Extensions/UIVIewController+Extensions...

45 lines
1.4 KiB
Swift
Raw Normal View History

2020-12-16 02:39:38 +01:00
// Copyright © 2020 Metabolist. All rights reserved.
2021-03-03 07:55:35 +01:00
import SafariServices
2020-12-16 02:39:38 +01:00
import UIKit
import ViewModels
extension UIViewController {
2021-03-09 05:40:22 +01:00
var isVisible: Bool { isViewLoaded && view.window != nil }
2021-03-06 06:48:11 +01:00
2020-12-16 02:39:38 +01:00
func present(alertItem: AlertItem) {
let alertController = UIAlertController(
title: nil,
message: alertItem.error.localizedDescription,
preferredStyle: .alert)
let okAction = UIAlertAction(title: NSLocalizedString("ok", comment: ""), style: .default) { _ in }
alertController.addAction(okAction)
present(alertController, animated: true)
}
2021-03-03 07:55:35 +01:00
#if !IS_SHARE_EXTENSION
func open(url: URL, identityContext: IdentityContext) {
func openWithRegardToBrowserSetting(url: URL) {
if identityContext.appPreferences.openLinksInDefaultBrowser || !url.isHTTPURL {
UIApplication.shared.open(url)
} else {
present(SFSafariViewController(url: url), animated: true)
}
}
if identityContext.appPreferences.useUniversalLinks {
UIApplication.shared.open(url, options: [.universalLinksOnly: true]) { success in
if !success {
openWithRegardToBrowserSetting(url: url)
}
}
} else {
openWithRegardToBrowserSetting(url: url)
}
}
#endif
2020-12-16 02:39:38 +01:00
}