Hi,
In my app I connected my app via TCP socket (global queue with serial) and get the data from the server and send it to the webView via wkWebview.evaluateJavascript in RunLoop.main
The data from socket is little bit huge and called evaluateJavaScript a hundred in minutes.
Everything works fine but after few seconds, I got below errors and my app's UI is whole blocked.
IConnection::dispatchIncomingMessages: IPC throttling was triggered (has 689 pending incoming messages, will only process 600 before yielding)
How could I fixed this and what's the problem?
Thanks.
In my app I connected my app via TCP socket (global queue with serial) and get the data from the server and send it to the webView via wkWebview.evaluateJavascript in RunLoop.main
Socket
Code Block Swift func socket(_ sock: GCDAsyncSocket, didRead data: Data, withTag tag: Int) { delegate?.onReceive(encodedData: data) self.socket?.readData(withTimeout: -1, tag: 0) }
Subject (Combine) for receiving from the socket
Code Block Swift self.onReceivedSubject .receive(on: RunLoop.main) .sink { (_) in } receiveValue: { [weak self] (info) in self?.callJavascriptFunc(function: WebConstants.JSFunction.socketDataReceived, param: "'\(info)'") }.store(in: &disposables)
Call evaluateJavascript
Code Block Swift private func callJavascriptFunc(function: String, param: String) { let functionWithParams = WebConstants.JSFunction.javascript + "\(function)(\(param));" webView?.evaluateJavaScript(functionWithParams, completionHandler: { (result, error) in // Do nothing.. }) }
The data from socket is little bit huge and called evaluateJavaScript a hundred in minutes.
Everything works fine but after few seconds, I got below errors and my app's UI is whole blocked.
IConnection::dispatchIncomingMessages: IPC throttling was triggered (has 689 pending incoming messages, will only process 600 before yielding)
How could I fixed this and what's the problem?
Thanks.
This is my solution.
In my program, below code called in many times and seems this evaluateJavascript waits until its completionHandler arrive with blocking other process. In other words this produces lots of messages which can be processed than expected. Finally it blocks process.
So my solution is to run Run loop while it waits its completionHandler.
In my program, below code called in many times and seems this evaluateJavascript waits until its completionHandler arrive with blocking other process. In other words this produces lots of messages which can be processed than expected. Finally it blocks process.
Code Block webView?.evaluateJavaScript(functionWithParams, completionHandler: { (result, error) in })
So my solution is to run Run loop while it waits its completionHandler.
Code Block webView?.evaluateJavaScript(functionWithParams, completionHandler: { (result, error) in isFinished = true }) /// Prevent no to block the thread, just run once before receving the response. while !isFinished { RunLoop.current.run(mode: .default, before: Date.distantFuture) }