Skip to content

Commit

Permalink
Script message handler for webview didn't get cleaned up properly (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
mroloux authored Aug 26, 2024
1 parent 748a267 commit 51af240
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ class SeatingChartSample: UIViewController {
self.view = seatsio
}

override func viewDidDisappear(_ animated: Bool) {
seatsio.cleanup()
}
}
```

Expand Down
7 changes: 3 additions & 4 deletions seatsio-ios/JustBridge.swift
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ public class JustBridge: NSObject {
self.injectBridgeJS()
}

public func cleanUp() {
self.webview!.configuration.userContentController.removeScriptMessageHandler(forName: "bridge")
}

/// Register a handler
/// Handler will be invoked when js call this handler
Expand All @@ -150,7 +153,6 @@ public class JustBridge: NSObject {
self.handlers.removeValue(forKey: name)
}


/// Call a js handler
///
/// - Parameters:
Expand Down Expand Up @@ -229,6 +231,3 @@ extension JustBridge: WKScriptMessageHandler {
}

}



3 changes: 3 additions & 0 deletions seatsio-ios/SeatsioWebView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,9 @@ public class SeatsioWebView: WKWebView {
"""
}

public func cleanup() {
bridge.cleanUp()
}
}

private func firstArg(_ data: Any?) -> Any {
Expand Down

0 comments on commit 51af240

Please sign in to comment.