Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bridge stops receiving messages after call is cancelled/fails #19

Open
steventnorris-40AU opened this issue Jun 20, 2017 · 1 comment
Open

Comments

@steventnorris-40AU
Copy link

If you get a loading failure, calling didFailLoadWithError on your delegate, the bridge no longer receives or responds to any JS messages passed, as if the bridge connection is severed. In my case, I reload links into the same web view, so after a single failure, no subsequent loads handle JS messages.

@steventnorris-40AU
Copy link
Author

steventnorris-40AU commented Jun 20, 2017

Further investigation:

If you instantiate the bridge and reconnect it to the webview on failure, you can get the bridge working again, but of course that's because I reconnect a new bridge.

In addition, if you declare a delegate after the bridge, the bridge does not work.

I use an "initializeBridge" method on init of the view. I then call that method again on my delegate's "didFailLoadWithError". This is a workaround, but does not seem to be intended functionality.

EX:

This works:

private func initializeBridge() {
        self.delegate = self

        bridge = SwiftWebViewBridge.bridge(self, defaultHandler: { _ , _ in print("DEFAULT") })
        bridge.registerHandlerForJS(handlerName: "shotPlaced") { jsonData, responseCallback in
            guard let jsonDict = jsonData as? [Double] else {
                print("SHOT PLACED")
                self.onShotPlaced?(.error)
                return
            }
            
            let pos: FloorPosition = (jsonDict[0], jsonDict[1])
            self.onShotPlaced?(.success(pos))
        }
        bridge.registerHandlerForJS(handlerName: "courtLoaded") { jsonData, responseCallback in
            print("JS MESSAGE")
            self.loadingIndicator.stopAnimating()
        }
    }

This does not:

private func initializeBridge() {
        bridge = SwiftWebViewBridge.bridge(self, defaultHandler: { _ , _ in print("DEFAULT") })
        bridge.registerHandlerForJS(handlerName: "shotPlaced") { jsonData, responseCallback in
            guard let jsonDict = jsonData as? [Double] else {
                print("SHOT PLACED")
                self.onShotPlaced?(.error)
                return
            }
            
            let pos: FloorPosition = (jsonDict[0], jsonDict[1])
            self.onShotPlaced?(.success(pos))
        }
        bridge.registerHandlerForJS(handlerName: "courtLoaded") { jsonData, responseCallback in
            print("JS MESSAGE")
            self.loadingIndicator.stopAnimating()
        }

        self.delegate = self
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant