Skip to content

Instantly share code, notes, and snippets.

@davidmuzi
Created September 22, 2017 00:33
Swift bridge
func userContentController(_ userContentController: WKUserContentController, didReceive message: WKScriptMessage) {
guard let type = EmbeddedAppMessageType(rawValue: message.name) else { return }
switch type {
case .setTitle:
let title = message.body as? String
setTitle(title: title)
case .loadingOn:
startActivityIndicator(start: true)
case .loadingOff:
startActivityIndicator(start: false)
case .setPrimaryButton:
guard let payload = [message.body] as? [[String: Any]] else {
setPrimaryButton(button: nil)
return
}
let primaryButton: EmbeddedAppButton? = EmbeddedAppButton.create(payload: payload).first
setPrimaryButton(button: primaryButton)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment