ios com.apple.WebKit.WebContent 丢弃 113 错误:找不到指定的服务

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/44585980/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 09:14:30  来源:igfitidea点击:

com.apple.WebKit.WebContent drops 113 error: Could not find specified service

ioswebkitwkwebview

提问by Ievgen Gavrysh

I am using WKWebViewfor viewing custom HTML.

我正在使用WKWebView查看自定义 HTML。

  • Regardless of HTML content, when testing on real device, I receive the following error Could not signal service com.apple.WebKit.WebContent: 113: Could not find specified servicein 29 sec after WKWebViewcontent loaded, sometimes I even receive this error twice. Clearly, it is a configuration issue. I have checked cookies as proposed in Could not signal service com.apple.WebKit.WebContent, however it doesn't help
  • Another question is whether there exist a list of all error codes that might pop up in WKWebView
  • 不管 HTML 内容如何,​​在真实设备上测试时,我Could not signal service com.apple.WebKit.WebContent: 113: Could not find specified serviceWKWebView内容加载后 29 秒内收到以下错误,有时我什至两次收到此错误。很明显,这是一个配置问题。我已经按照无法发出信号服务 com.apple.WebKit.WebContent 中的建议检查了 cookie ,但是它没有帮助
  • 另一个问题是是否存在WKWebView中可能弹出的所有错误代码的列表

回答by Ievgen Gavrysh

Finally, solved the problem above. I was receiving errors

最后,解决了上面的问题。我收到错误

  • Could not signal service com.apple.WebKit.WebContent: 113: Could not find specified service
  • Could not signal service com.apple.WebKit.WebContent: 113: Could not find specified service

Since I have not added WKWebViewobject on the view as a subview and tried to call -loadHTMLString:baseURL:on the top of it. And only after it was successfully loaded I was adding it to view's subviews - which was totally wrong. The correct solution for my problem is:

由于我没有在视图上添加WKWebView对象作为子视图并尝试-loadHTMLString:baseURL:在它的顶部调用。只有在它成功加载后,我才将它添加到视图的子视图中——这是完全错误的。我的问题的正确解决方案是:

1.Add WKWebViewobject to view's subviewsarray

1.WKWebView对象添加到视图的subviews数组中

2.Call -loadHTMLString:baseURL:for recently added WKWebView

2.调用-loadHTMLString:baseURL:最近添加的WKWebView

回答by Asad Khan

I too faced this problem when loading an 'http' url in WKWebViewin iOS 11, it is working fine with https.

在 iOS 11 的WKWebView中加载“http”网址时,我也遇到了这个问题,它与 https 一起工作正常。

What worked for me was setting App transport setting in info.pist file to allow arbitary load.

对我有用的是在 info.pist 文件中设置 App 传输设置以允许任意加载。

<key>NSAppTransportSecurity</key>
    <dict>
        <!--Not a recommended way, there are better solutions available-->
        <key>NSAllowsArbitraryLoads</key>
        <true/>
    </dict>

回答by yusuke024

Maybe it's an entirely different situation, but I always got WebView[43046:188825] Could not signal service com.apple.WebKit.WebContent: 113: Could not find specified service when opening a webpage on the simulator while having the debugger attached to it. If I end the debugger and opening the app again the webpage will open just fine. This doesn't happen on the devices.

也许这是一种完全不同的情况,但是WebView[43046:188825] Could not signal service com.apple.WebKit.WebContent: 113: Could not find specified service 当我在模拟器上打开网页时我总是遇到调试器附加到它的情况。如果我结束调试器并再次打开应用程序,网页将打开就好了。这不会发生在设备上。

After spending an entire work-day trying to figure out what's wrong, I found out that if we have a framework named Preferences, UIWebViewand WKWebViewwill not be able to open a webpage and will throw the error above.

花一整个工作一天试图找出什么是错的,我发现,如果我们有一个框架命名PreferencesUIWebView并且WKWebView将不能够打开一个网页,将抛出上述错误。

To reproduce this error just make a simple app with WKWebViewto show a webpage. Then create a new framework target and name it Preferences. Then import it to the main target and run the simulator again. WKWebViewwill fail to open a webpage.

要重现此错误,只需制作一个简单的应用程序WKWebView即可显示网页。然后创建一个新的框架目标并将其命名为Preferences. 然后将其导入主目标并再次运行模拟器。WKWebView将无法打开网页。

So, it might be unlikely, but if you have a framework with the name Preferences, try deleting or renaming it.

因此,这可能不太可能,但如果您有一个名为 的框架Preferences,请尝试删除或重命名它。

Also, if anyone has an explanation for this please do share.

另外,如果有人对此有解释,请分享。

BTW, I was on Xcode 9.2.

顺便说一句,我使用的是 Xcode 9.2。

回答by Markus

I got this error loading a http:// URL where the server replied with a redirect to https. After changing the URL I pass to WKWebView to https://... it worked.

我在加载 http:// URL 时遇到此错误,其中服务器回复重定向到 https。将我传递给 WKWebView 的 URL 更改为 https://...后,它起作用了。

回答by Abhishek Mitra

SWIFT

迅速

Well I did this in the following order and didn't get any error like Could not signal service com.apple.WebKit.WebContent: 113: Could not find specified serviceafter that, following code might help you too.

好吧,我按照以下顺序执行此操作,之后没有出现任何错误Could not signal service com.apple.WebKit.WebContent: 113: Could not find specified service,以下代码也可能对您有所帮助。

webView = WKWebView(frame: self.view.frame)
self.view.addSubview(self.view.webView)
webView.navigationDelegate = self
webView.loadHTMLString(htmlString, baseURL: nil)

Do as order.

按顺序做。

Thanks

谢谢

回答by Peter B. Kramer

In my case I was launching a WKWebView and displaying a website. Then (within 25 seconds) I deallocated the WKWebView. But 25-60 seconds after launching the WKWebView I received this "113" error message. I assume the system was trying to signal something to the WKWebView and couldn't find it because it was deallocated.

就我而言,我正在启动一个 WKWebView 并显示一个网站。然后(在 25 秒内)我释放了 WKWebView。但是在启动 WKWebView 25-60 秒后,我收到了此“113”错误消息。我假设系统试图向 WKWebView 发送信号,但找不到它,因为它已被释放。

The fix was simply to leave the WKWebView allocated.

修复只是保留 WKWebView 分配。

回答by Guy Lowe

Mine was different again. I was setting the user-agent like so:

我的又不一样了。我是这样设置用户代理的:

    NSString *jScript = @"var meta = document.createElement('meta'); meta.setAttribute('name', 'viewport'); meta.setAttribute('content', 'width=device-width'); document.getElementsByTagName('head')[0].appendChild(meta);";
    WKUserScript *wkUScript = [[WKUserScript alloc] initWithSource:jScript injectionTime:WKUserScriptInjectionTimeAtDocumentEnd forMainFrameOnly:YES];

This was causing something on the web page to freak out and leak memory. Not sure why but removing this sorted the issue for me.

这导致网页上的某些内容出现异常并泄漏内存。不知道为什么,但删除它为我解决了这个问题。

回答by Pradheep Narendran P

Perhaps the below method could be the cause if you've set it to

如果您将其设置为以下方法,则可能是原因

func webView(_ webView: WebView!,decidePolicyForNavigationAction actionInformation: [AnyHashable : Any]!, request: URLRequest!, frame: WebFrame!, decisionListener listener: WebPolicyDecisionListener!) 

ends with

以。。结束

decisionHandler(.cancel)

for the default navigationAction.request.url

对于默认 navigationAction.request.url

Hope it works!

希望它有效!

回答by Juanmi

On OS X, it's necessary to make sure Sandbox capabilities are set-up properly in order to use WKWebView.

在 OS X 上,有必要确保正确设置沙箱功能才能使用 WKWebView。

This link made this clear to me: https://forums.developer.apple.com/thread/92265

这个链接让我很清楚:https: //forums.developer.apple.com/thread/92265

Sharing hoping that it will help someone.

分享希望它会帮助某人。



Select the Project File in the Navigator, select Capabilities, then make sure that:
* App Sandbox is OFF,
OR
* App Sandbox is ON AND Outgoing Connections (Client) is checked.

在导航器中选择项目文件,选择功能,然后确保:
* App Sandbox 已关闭,

* App Sandbox 已打开且已选中 Outgoing Connections (Client)。

回答by Dom Barnes

Just for others reference, I seemed to have this issue too if I tried to load a URL that had whitespace at the end (was being pulled from user input).

仅供其他人参考,如果我尝试加载末尾有空格的 URL(从用户输入中提取),我似乎也遇到了这个问题。