Recently, I encountered a thorny problem. First, I would like to describe the problem: The Webview used for help feedback in our project. The webview calls the native method to request data, and then after success, we send the data back to H5 through a method agreed by H5, and they are responsible for display. However, there is a problem in the recent test: the feedback page is loaded, and the data on the third page is required to keep loading until timeout. After debugging, I finally located the problem: it turned out that there were special characters in the data on the third page, and then the following method of CALLING JS reported an error

  if (script) {
            [self.webView evaluateJavaScript:script completionHandler:^(id _Nullable result, NSError * _Nullable error) {
                if (result) {
                    
                }
                if (error) {
                    
                }
            }];
        }
Copy the code

Baidu Google for a long time, the results say most is to say that I call the timing is wrong, obviously I am not here for this reason. I’m reporting an error here because there is a problem with the string I concatenated. Although I know the general cause, I still haven’t found a solution. Until I asked my classmate, he had studied the source code of WKWebViewBridge before, and said there was a similar place in it. Sure enough, I pasted out the method of string processing inside, and the problem was solved.

Js online format check