Skip to content

Commit

Permalink
Fix compile errors on Xcode 12.4 and bellow
Browse files Browse the repository at this point in the history
  • Loading branch information
gwdp committed Apr 8, 2022
1 parent 4dd0be4 commit b4fcf84
Showing 1 changed file with 30 additions and 12 deletions.
42 changes: 30 additions & 12 deletions ios/Capacitor/Capacitor/WebViewDelegationHandler.swift
Expand Up @@ -2,6 +2,11 @@ import Foundation
import WebKit
import MobileCoreServices

// TODO: remove once Xcode 12 support is dropped
#if compiler(<5.5)
protocol WKDownloadDelegate {}
#endif

// adopting a public protocol in an internal class is by design
// swiftlint:disable lower_acl_than_parent
@objc(CAPWebViewDelegationHandler)
Expand Down Expand Up @@ -82,13 +87,16 @@ internal class WebViewDelegationHandler: NSObject, WKNavigationDelegate, WKUIDel
// post a notification for any listeners
NotificationCenter.default.post(name: .capacitorDecidePolicyForNavigationAction, object: navigationAction)

// check if we can detect file download on iOS >= 14.5
if #available(iOS 14.5, *) {
if navigationAction.shouldPerformDownload {
decisionHandler(.download)
return
// TODO: remove once Xcode 12 support is dropped
#if compiler(>=5.5)
// check if we can detect file download on iOS >= 14.5
if #available(iOS 14.5, *) {
if navigationAction.shouldPerformDownload {
decisionHandler(.download)
return
}
}
}
#endif

// sanity check, these shouldn't ever be nil in practice
guard let bridge = bridge, let navURL = navigationAction.request.url else {
Expand Down Expand Up @@ -172,11 +180,14 @@ internal class WebViewDelegationHandler: NSObject, WKNavigationDelegate, WKUIDel
return
}
}
// Download support for iOS >= 14.5
if #available(iOS 14.5, *) {
decisionHandler(.download)
return
}
// TODO: remove once Xcode 12 support is dropped
#if compiler(>=5.5)
// Download support for iOS >= 14.5
if #available(iOS 14.5, *) {
decisionHandler(.download)
return
}
#endif
// Deny if not recognize until now and webView can not
// show the specified MIME type
decisionHandler(.cancel)
Expand All @@ -186,6 +197,9 @@ internal class WebViewDelegationHandler: NSObject, WKNavigationDelegate, WKUIDel
webView.reload()
}

// TODO: remove once Xcode 12 support is dropped
#if compiler(>=5.5)

@available(iOS 14.5, *)
func webView(_ webView: WKWebView, navigationAction: WKNavigationAction, didBecome download: WKDownload) {
CAPLog.print("⚡️ Initiating background download..")
Expand All @@ -196,6 +210,8 @@ internal class WebViewDelegationHandler: NSObject, WKNavigationDelegate, WKUIDel
CAPLog.print("⚡️ Initiating background download..")
download.delegate = self
}

#endif

// MARK: - WKScriptMessageHandler

Expand Down Expand Up @@ -312,7 +328,8 @@ internal class WebViewDelegationHandler: NSObject, WKNavigationDelegate, WKUIDel
}

// MARK: - WKDownloadDelegate

// TODO: remove once Xcode 12 support is dropped
#if compiler(>=5.5)
@available(iOS 14.5, *)
public func download(_ download: WKDownload, decideDestinationUsing response: URLResponse, suggestedFilename: String, completionHandler: @escaping (URL?) -> Void) {
// Add pending download
Expand Down Expand Up @@ -345,6 +362,7 @@ internal class WebViewDelegationHandler: NSObject, WKNavigationDelegate, WKUIDel
"status": FileDownloadNotificationStatus.failed
])
}
#endif

// MARK: - UIDocumentPickerDelegate

Expand Down

0 comments on commit b4fcf84

Please sign in to comment.