Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

184
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!