-
Notifications
You must be signed in to change notification settings - Fork 6
Differences with DSBridge‐iOS
When using the old DSBridge-iOS, in order to implement WKWebView.uiDelegate
, you'd have to set dsuiDelegate
instead. In DSBridge-Swift, you can just set uiDelegate
.
The old dsuiDelegate
does not respond to new APIs, such as one that's released on iOS 16.4:
@available(iOS 16.4, *)
func webView(
_ webView: WKWebView,
willPresentEditMenuWithAnimator animator: any UIEditMenuInteractionAnimating
) {
}
Even if your dsuiDelegate
does implement it, it won't get called on text selections or editing menu animations. The reason is that the old DSBridge-iOS relay those API calls to you by implementing them ahead of time and calling dsuiDelegate
inside those implementations. This causes it to suffer from iOS iterations. Especially that it crashes when it tries to use the deprecated UIAlertView
.
DSBridge-Swift, instead, makes better use of iOS Runtime features to avoid standing between you and the web view. You can set the uiDelegate
to your own object just like what you do with bare WKWebView
and all the delegation methods will work as if DSBridge is not there.
On the contrary, you'd have to do the dialog thing yourself. And all the dialog related APIs are removed, along with the dsuiDelegate
.
When using the old DSBridge-iOS, your JavaScript Object has to be an NSObject
subclass. Functions in it have to be prefixed with @objc
. DSBridge-Swift, however, is much more Swift-ish. You can use pure Swift types like class
or even struct
and enum
.
DSBridge-Swift provides highly customizable flexibility which allows you to change almost any part of it. You can even extends it to use it with another piece of completely different JavaScript. See section Open / Close Principle below.
A new calling method that allows you to specify the expected return type and returns a Result<T, Error>
instead of an Any
.
call<T>(
_: String,
with: [Any],
thatReturns: T.Type,
completion: @escaping (Result<T, any Swift.Error>) -> Void
)
-
callHandler
is renamed tocall
-
setJavascriptCloseWindowListener
todismissalHandler
-
addJavascriptObject
toaddInterface
-
removeJavascriptObject
toremoveInterface
-
loadUrl(_: String)
is removed. Define your own one if you need it -
onMessage
, a public method that's supposed to be private, is removed -
dsuiDelegate
-
disableJavascriptDialogBlock
-
customJavascriptDialogLabelTitles
-
and all the
WKUIDelegate
implementations
- Debug mode not implemented yet.