21 lines
589 B
Swift
21 lines
589 B
Swift
import Foundation
|
|
import WebKit
|
|
|
|
/// Use to avoid holding webview alive when adding WKScriptMessageHandler
|
|
final class SafeScriptMessageHandler: NSObject, WKScriptMessageHandler {
|
|
weak var delegate: WKScriptMessageHandler?
|
|
init(delegate: WKScriptMessageHandler) {
|
|
self.delegate = delegate
|
|
super.init()
|
|
}
|
|
|
|
func userContentController(
|
|
_ userContentController: WKUserContentController,
|
|
didReceive message: WKScriptMessage
|
|
) {
|
|
delegate?.userContentController(
|
|
userContentController, didReceive: message
|
|
)
|
|
}
|
|
}
|