forked from shadowfacts/Tusker
Fix crash when tapping non-HTTP(S) links with In-App Safari enabled
This commit is contained in:
parent
daa1a9eef7
commit
b0bd27db31
|
@ -2,6 +2,11 @@
|
||||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||||
<plist version="1.0">
|
<plist version="1.0">
|
||||||
<dict>
|
<dict>
|
||||||
|
<key>LSApplicationQueriesSchemes</key>
|
||||||
|
<array>
|
||||||
|
<string>gopher</string>
|
||||||
|
<string>gemini</string>
|
||||||
|
</array>
|
||||||
<key>CFBundleDevelopmentRegion</key>
|
<key>CFBundleDevelopmentRegion</key>
|
||||||
<string>$(DEVELOPMENT_LANGUAGE)</string>
|
<string>$(DEVELOPMENT_LANGUAGE)</string>
|
||||||
<key>CFBundleExecutable</key>
|
<key>CFBundleExecutable</key>
|
||||||
|
@ -51,7 +56,7 @@
|
||||||
<key>NSMicrophoneUsageDescription</key>
|
<key>NSMicrophoneUsageDescription</key>
|
||||||
<string>Post videos from the camera.</string>
|
<string>Post videos from the camera.</string>
|
||||||
<key>NSPhotoLibraryAddUsageDescription</key>
|
<key>NSPhotoLibraryAddUsageDescription</key>
|
||||||
<string>Save photos directly from other people's posts.</string>
|
<string>Save photos directly from other people's posts.</string>
|
||||||
<key>NSPhotoLibraryUsageDescription</key>
|
<key>NSPhotoLibraryUsageDescription</key>
|
||||||
<string>Post photos from the photo library.</string>
|
<string>Post photos from the photo library.</string>
|
||||||
<key>NSUserActivityTypes</key>
|
<key>NSUserActivityTypes</key>
|
||||||
|
|
|
@ -46,16 +46,26 @@ extension TuskerNavigationDelegate {
|
||||||
|
|
||||||
func selected(url: URL, allowUniversalLinks: Bool = true) {
|
func selected(url: URL, allowUniversalLinks: Bool = true) {
|
||||||
func openSafari() {
|
func openSafari() {
|
||||||
if Preferences.shared.useInAppSafari {
|
if Preferences.shared.useInAppSafari,
|
||||||
|
url.scheme == "https" || url.scheme == "http" {
|
||||||
let config = SFSafariViewController.Configuration()
|
let config = SFSafariViewController.Configuration()
|
||||||
config.entersReaderIfAvailable = Preferences.shared.inAppSafariAutomaticReaderMode
|
config.entersReaderIfAvailable = Preferences.shared.inAppSafariAutomaticReaderMode
|
||||||
present(SFSafariViewController(url: url, configuration: config), animated: true)
|
present(SFSafariViewController(url: url, configuration: config), animated: true)
|
||||||
} else {
|
} else if UIApplication.shared.canOpenURL(url) {
|
||||||
UIApplication.shared.open(url, options: [:])
|
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
|
UIApplication.shared.open(url, options: [.universalLinksOnly: true]) { (success) in
|
||||||
if (!success) {
|
if (!success) {
|
||||||
openSafari()
|
openSafari()
|
||||||
|
|
Loading…
Reference in New Issue