Description
I've seen this issue when I use WKWebView
in SwiftUI. If I have 2 web views at once in a SwiftUI view, it produces unwanted console warnings that seem to be not solvable on client side.
The warnings aren't present when there is only 1 web view.
Similar warnings regarding the "running board" or RBSAssertionErrorDomain
are reported by others as well.
Please advice how to dismiss these warnings in the app. Thank you.
Repro Steps and Code
- Create a new iOS project.
- Put the following code into
ContentView.swift
. It wraps aWKWebView
in SwiftUI and display some dummy html data in the web views. - Build and run the app.
- Tap the info button.
- Drag down or dismiss the sheet. Upon dismiss, in the console it prints the error messages attached below.
import SwiftUI
import WebKit
struct ContentView: View {
@State private var isInfoViewPresented = false
@State private var selectedIndex = 0
func makeErrorHTML(index: Int) -> String {
#"<!doctype html><html><h1 style="text-align: center;">Unable to display README.</h1></html>"#
}
var body: some View {
VStack(spacing: 8) {
Text("Hello, world!")
Button {
isInfoViewPresented = true
} label: {
Image(systemName: "info.circle")
.imageScale(.large)
}
.sheet(isPresented: $isInfoViewPresented) {
sheetContent
}
}
}
var sheetContent: some View {
NavigationStack {
ZStack {
WebView(htmlString: makeErrorHTML(index: 0))
.background(Color(uiColor: .systemGray))
.opacity(selectedIndex == 0 ? 1 : 0)
WebView(htmlString: makeErrorHTML(index: 1))
.background(Color(uiColor: .systemGray2))
.opacity(selectedIndex == 1 ? 1 : 0)
}
.toolbar {
ToolbarItem(placement: .principal) {
Picker("Information Mode", selection: $selectedIndex) {
Text("0").tag(0)
Text("1").tag(1)
}
.pickerStyle(.segmented)
}
ToolbarItem(placement: .confirmationAction) {
Button("Done") {
isInfoViewPresented = false
}
}
}
}
}
}
struct WebView: UIViewRepresentable {
/// The HTML to load in the web view.
let htmlString: String
func makeUIView(context: Context) -> WKWebView {
// Creates an empty web view.
let webView = WKWebView(frame: .zero)
// Sets the web view's navigation delegate.
webView.navigationDelegate = context.coordinator
return webView
}
func updateUIView(_ webView: WKWebView, context: Context) {
// Loads the given HTML string.
webView.loadHTMLString(htmlString, baseURL: nil)
}
func makeCoordinator() -> Coordinator {
Coordinator()
}
class Coordinator: NSObject, WKNavigationDelegate {
func webView(
_ webView: WKWebView,
decidePolicyFor navigationAction: WKNavigationAction,
decisionHandler: @escaping (WKNavigationActionPolicy) -> Void
) {
switch navigationAction.navigationType {
case .linkActivated:
if let url = navigationAction.request.url, UIApplication.shared.canOpenURL(url) {
UIApplication.shared.open(url)
}
decisionHandler(.cancel)
default:
decisionHandler(.allow)
}
}
}
}
OS Version
- iOS 15 - iOS 17 Simulator and Device
- Xcode Version 15.0.1 (15A507)
- macOS 14.1.1 (23B81)
Similar Posts
- @eskimo shared information about
runningboard
in this post: https://developer.apple.com/forums/thread/702207 - https://developer.apple.com/forums/thread/709919
- https://stackoverflow.com/questions/69902932/error-acquiring-assertions-what-is-that
- https://developer.apple.com/forums/thread/708801
Error From Console
Error acquiring assertion: <Error Domain=RBSServiceErrorDomain Code=1 "target is not running or doesn't have entitlement com.apple.runningboard.assertions.webkit" UserInfo={NSLocalizedFailureReason=target is not running or doesn't have entitlement com.apple.runningboard.assertions.webkit}>
0x11e024780 - ProcessAssertion::acquireSync Failed to acquire RBS assertion 'XPCConnectionTerminationWatchdog' for process with PID=85,796, error: Error Domain=RBSServiceErrorDomain Code=1 "target is not running or doesn't have entitlement com.apple.runningboard.assertions.webkit" UserInfo={NSLocalizedFailureReason=target is not running or doesn't have entitlement com.apple.runningboard.assertions.webkit}
Error acquiring assertion: <Error Domain=RBSAssertionErrorDomain Code=2 "Specified target process does not exist" UserInfo={NSLocalizedFailureReason=Specified target process does not exist}>
0x11e0247e0 - ProcessAssertion::acquireSync Failed to acquire RBS assertion 'WebProcess NearSuspended Assertion' for process with PID=85,796, error: Error Domain=RBSAssertionErrorDomain Code=2 "Specified target process does not exist" UserInfo={NSLocalizedFailureReason=Specified target process does not exist}
Error acquiring assertion: <Error Domain=RBSServiceErrorDomain Code=1 "target is not running or doesn't have entitlement com.apple.runningboard.assertions.webkit" UserInfo={NSLocalizedFailureReason=target is not running or doesn't have entitlement com.apple.runningboard.assertions.webkit}>
0x11e0248a0 - ProcessAssertion::acquireSync Failed to acquire RBS assertion 'WebProcess NearSuspended Assertion' for process with PID=85,797, error: Error Domain=RBSServiceErrorDomain Code=1 "target is not running or doesn't have entitlement com.apple.runningboard.assertions.webkit" UserInfo={NSLocalizedFailureReason=target is not running or doesn't have entitlement com.apple.runningboard.assertions.webkit}