diff --git a/Source/AuthenticatedWebViewController.swift b/Source/AuthenticatedWebViewController.swift index 93fbe84b7..7aeec4eaa 100644 --- a/Source/AuthenticatedWebViewController.swift +++ b/Source/AuthenticatedWebViewController.swift @@ -457,6 +457,15 @@ public class AuthenticatedWebViewController: UIViewController, WKUIDelegate, WKN return requestURL.contains(type.rawValue) } + public func removeCallbackHandler() { + configurations.userContentController.removeAllUserScripts() + if #available(iOS 14.0, *) { + configurations.userContentController.removeAllScriptMessageHandlers() + } else { + configurations.userContentController.removeScriptMessageHandler(forName: AJAXCallBackHandler) + } + } + public func userContentController(_ userContentController: WKUserContentController, didReceive message: WKScriptMessage) { if message.name == AJAXCallBackHandler { guard let data = message.body as? Dictionary else { return } diff --git a/Source/CourseDatesViewController.swift b/Source/CourseDatesViewController.swift index 0e922ac00..c3f984864 100644 --- a/Source/CourseDatesViewController.swift +++ b/Source/CourseDatesViewController.swift @@ -25,7 +25,6 @@ class CourseDatesViewController: UIViewController, InterfaceOrientationOverridin private let datesLoader = BackedStream<(CourseDateModel, UserPreference?)>() private let courseDateBannerLoader = BackedStream<(CourseDateBannerModel)>() - private var stream: OEXStream<(CourseDateModel, UserPreference?)>? private lazy var tableView: UITableView = { let tableView = UITableView() @@ -177,10 +176,10 @@ class CourseDatesViewController: UIViewController, InterfaceOrientationOverridin let preferenceStream = environment.dataManager.userPreferenceManager.feed.output let networkRequest = CourseDatesAPI.courseDatesRequest(courseID: courseID) let datesStream = environment.networkManager.streamForRequest(networkRequest) - stream = joinStreams(datesStream, preferenceStream) - datesLoader.addBackingStream(datesLoader) + let stream = joinStreams(datesStream, preferenceStream) + datesLoader.addBackingStream(stream) - stream?.listen(self) { [weak self] response in + stream.listen(self) { [weak self] response in self?.refreshController.endRefreshing() switch response { case .success((var courseDateModel, let userPreference)): diff --git a/Source/HTMLBlockViewController.swift b/Source/HTMLBlockViewController.swift index 476e71b71..d4d1c71ef 100644 --- a/Source/HTMLBlockViewController.swift +++ b/Source/HTMLBlockViewController.swift @@ -253,6 +253,7 @@ class HTMLBlockViewController: UIViewController, CourseBlockViewController, Prel } deinit { + webController.removeCallbackHandler() NotificationCenter.default.removeObserver(self) } }