WKWebView 正在尝试在后台运行,尽管它已关闭并且应该被处理 [英] WKWebView is trying to run on background, although it's closed and should be disposed

查看:479
本文介绍了WKWebView 正在尝试在后台运行,尽管它已关闭并且应该被处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在应用程序的 UIViewController 容器中有一个简单的 WKWebView.用户将使用 WKWebView 打开这个 UIViewController 容器,然后最终将使用导航返回"关闭它.物品.导航项配置容器和WKWebView.它有效,但在每次关闭时,我都会在日志中看到以下错误:

第一对错误:

<块引用>

[assertion] 获取断言时出错:<Error Domain=RBSAssertionErrorDomain Code=3 目标未运行或缺少所需的目标权利"用户信息={RBSAssertionAttribute=<RBSDomainAttribute|域:com.apple.webkit"名称:背景"sourceEnvironment:"(null)">, NSLocalizedFailureReason=目标未运行或缺少所需的目标权限}>

<块引用>

[ProcessSuspension] 0x7f8f9d404210 - ProcessAssertion:无法获取 PID 为 27176 的进程的 RBS 后台断言WebProcess 后台断言",错误:错误域=RBSAssertionErrorDomain 代码=3目标未运行或缺少所需的目标权利"用户信息={RBSAssertionAttribute=<RBSDomainAttribute|域:com.apple.webkit"名称:背景"sourceEnvironment:"(null)">, NSLocalizedFailureReason=目标未运行或缺少所需的目标权限}

第二对错误:

<块引用>

[assertion] 获取断言时出错:<Error Domain=RBSAssertionErrorDomain Code=2 指定的目标进程不存在";UserInfo={NSLocalizedFailureReason=指定的目标进程不存在}>

<块引用>

[ProcessSuspension] 0x7f8f9d005c30 - ProcessAssertion:无法获取 PID 为 27176 的进程的 RBS 后台断言WebProcess 后台断言",错误:错误域 = RBSAssertionErrorDomain 代码 = 2指定的目标进程不存在";UserInfo={NSLocalizedFailureReason=指定的目标进程不存在}

第三对错误:

<块引用>

无法向服务 com.apple.WebKit.WebContent 发出信号:113:找不到指定的服务

<块引用>

无法向服务 com.apple.WebKit.Networking 发出信号:113:找不到指定的服务

WKWebView 是从容器 UIViewController 的 viewDidDisappear(也尝试将其移动到 viewWillDisappear,这没有什么区别)以如下方式处理的:

webView.stopLoading()webView.configuration.userContentController.removeScriptMessageHandler(forName: "...")webView.navigationDelegate = nilwebView.scrollView.delegate = nil网络视图 = 零

这些错误似乎没有负面影响.但我想了解:我是否缺少对 WKWebView 处理的一些清理?为什么它试图进入背景"?

解决方案

我面临同样的问题,发现以下两个有趣的主题:

  1. https://developer.apple.com/forums/thread/112095Apple 支持人员声称这些警告(例如,无法向服务 com.apple.WebKit.Networking 发出信号:113:找不到指定的服务)不是您应该担心的事情
  2. Xcode 8, iOS 10 - "启动 WebFilter 日志记录对于进程,这是帮助我消除这些警告的唯一解决方案.基本上,你应该设置 OS_ACTIVITY_MODE = disable

I have a simple WKWebView in a UIViewController container in the application. User will open this UIViewController container with WKWebView, and then will eventually close it with navigation "Back" item. The navigation item disposes container and WKWebView. It works, but on every closure I see the following errors in the log:

First pair of errors:

[assertion] Error acquiring assertion: <Error Domain=RBSAssertionErrorDomain Code=3 "Target is not running or required target entitlement is missing" UserInfo={RBSAssertionAttribute=<RBSDomainAttribute| domain:"com.apple.webkit" name:"Background" sourceEnvironment:"(null)">, NSLocalizedFailureReason=Target is not running or required target entitlement is missing}>

[ProcessSuspension] 0x7f8f9d404210 - ProcessAssertion: Failed to acquire RBS Background assertion 'WebProcess Background Assertion' for process with PID 27176, error: Error Domain=RBSAssertionErrorDomain Code=3 "Target is not running or required target entitlement is missing" UserInfo={RBSAssertionAttribute=<RBSDomainAttribute| domain:"com.apple.webkit" name:"Background" sourceEnvironment:"(null)">, NSLocalizedFailureReason=Target is not running or required target entitlement is missing}

Second pair of errors:

[assertion] Error acquiring assertion: <Error Domain=RBSAssertionErrorDomain Code=2 "Specified target process does not exist" UserInfo={NSLocalizedFailureReason=Specified target process does not exist}>

[ProcessSuspension] 0x7f8f9d005c30 - ProcessAssertion: Failed to acquire RBS Background assertion 'WebProcess Background Assertion' for process with PID 27176, error: Error Domain=RBSAssertionErrorDomain Code=2 "Specified target process does not exist" UserInfo={NSLocalizedFailureReason=Specified target process does not exist}

Third pair of errors:

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

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

The WKWebView is disposed from container UIViewController's viewDidDisappear (also tried to move it to viewWillDisappear, which made no difference) in the following way:

webView.stopLoading()
webView.configuration.userContentController.removeScriptMessageHandler(forName: "...")
webView.navigationDelegate = nil
webView.scrollView.delegate = nil
webView = nil

There's no negative side effects of those errors it seems. But I want to understand: am I missing some cleanup on WKWebView disposal? Why does it try to "enter background"?

解决方案

I am facing same issues and found these two interesting threads:

  1. https://developer.apple.com/forums/thread/112095 where a guy from Apple's support claims that these warnings (e.g. Could not signal service com.apple.WebKit.Networking: 113: Could not find specified service) aren't something you should worry about
  2. Xcode 8, iOS 10 - "Starting WebFilter logging for process" this was the only solution that helped me silence these warnings. Basically, you should set OS_ACTIVITY_MODE = disable

这篇关于WKWebView 正在尝试在后台运行,尽管它已关闭并且应该被处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆