Skip to content

Commit

Permalink
Wrap openURL for app extensions
Browse files Browse the repository at this point in the history
- DownView couldn’t compile in app extensions because of the use of UIApplication.shared.openURL
- With this change, an empty wrapper is used to allow DownView to compile and be usable in app extensions, with the downside that links cannot be opened
  • Loading branch information
nheagy committed Apr 9, 2019
1 parent a146258 commit 3b3e833
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions Source/Views/DownView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -174,19 +174,31 @@ extension DownView: WKNavigationDelegate {
}

decisionHandler(.cancel)
#if os(iOS)
UIApplication.shared.openURL(url)
#elseif os(macOS)
NSWorkspace.shared.open(url)
#endif
openURL(url: url)
default:
decisionHandler(.allow)
}
}

@available(iOSApplicationExtension, unavailable)
func openURL(url: URL) {
#if os(iOS)
UIApplication.shared.openURL(url)
#elseif os(macOS)
NSWorkspace.shared.open(url)
#endif
}

public func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
didLoadSuccessfully?()
}

}

fileprivate extension WKNavigationDelegate {
/// A wrapper for `UIApplication.shared.openURL` so that an empty default
/// implementation is available in app extensions
public func openURL(url: URL) {}
}

#endif

0 comments on commit 3b3e833

Please sign in to comment.