Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

185
Visualizações
WKUserContentController message handling not working in swift

// whenever I load any URL in my webview , then this callbackhadler must work when called by javascript in loaded website/URL, but it doesn't get called, in my case, I m working on payment portal and after success/failed payment website must call this callbackHandler

// view did load

override func viewDidLoad() {
    super.viewDidLoad()
    let contentController = WKUserContentController()
        contentController.add(self, name: "callbackHandler")
        contentController.add(self, contentWorld: .defaultClient, name:         
    "callbackHandler")
    
    let config = WKWebViewConfiguration()
    config.ignoresViewportScaleLimits = true
    
    config.userContentController = contentController
    config.preferences.javaScriptCanOpenWindowsAutomatically = true
    config.defaultWebpagePreferences.allowsContentJavaScript = true
    
    self.webView = WKWebView( frame: .zero, configuration: config)
   
}



func userContentController(_ userContentController: WKUserContentController, didReceive message: WKScriptMessage) {// edit: changed fun to func
    if (message.name == "callbackHandler"){
        print("with boby mesage \(message.body)")
    }
    
}

here is the article provided by payment company which suggested this method in the first place,

userContentController never called back from JS injection

about 4 years ago · Santiago Gelvez
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda