diff --git a/Tusker/Info.plist b/Tusker/Info.plist index f4d5d9eb..d07fd5e5 100644 --- a/Tusker/Info.plist +++ b/Tusker/Info.plist @@ -2,6 +2,11 @@ + LSApplicationQueriesSchemes + + gopher + gemini + CFBundleDevelopmentRegion $(DEVELOPMENT_LANGUAGE) CFBundleExecutable @@ -51,7 +56,7 @@ NSMicrophoneUsageDescription Post videos from the camera. NSPhotoLibraryAddUsageDescription - Save photos directly from other people's posts. + Save photos directly from other people's posts. NSPhotoLibraryUsageDescription Post photos from the photo library. NSUserActivityTypes diff --git a/Tusker/TuskerNavigationDelegate.swift b/Tusker/TuskerNavigationDelegate.swift index 39d4c353..7f2a1b8a 100644 --- a/Tusker/TuskerNavigationDelegate.swift +++ b/Tusker/TuskerNavigationDelegate.swift @@ -46,16 +46,26 @@ extension TuskerNavigationDelegate { func selected(url: URL, allowUniversalLinks: Bool = true) { func openSafari() { - if Preferences.shared.useInAppSafari { + if Preferences.shared.useInAppSafari, + url.scheme == "https" || url.scheme == "http" { let config = SFSafariViewController.Configuration() config.entersReaderIfAvailable = Preferences.shared.inAppSafariAutomaticReaderMode present(SFSafariViewController(url: url, configuration: config), animated: true) - } else { + } else if UIApplication.shared.canOpenURL(url) { UIApplication.shared.open(url, options: [:]) + } else { + var message = "The URL could not be opened." + if let scheme = url.scheme { + message += " This can happen if you do not have an app installed for '\(scheme)://' URLs." + } + let alert = UIAlertController(title: "Invalid URL", message: message, preferredStyle: .alert) + alert.addAction(UIAlertAction(title: "Ok", style: .default, handler: nil)) + present(alert, animated: true) } } - if allowUniversalLinks && Preferences.shared.openLinksInApps { + if allowUniversalLinks && Preferences.shared.openLinksInApps, + url.scheme == "https" || url.scheme == "http" { UIApplication.shared.open(url, options: [.universalLinksOnly: true]) { (success) in if (!success) { openSafari()