SwiftUI-WKWebView的iOS 13 UIViewRepresentable出现线程1:EXC_BREAKPOINT崩溃 [英] SwiftUI - iOS 13 UIViewRepresentable of WKWebView gets Thread 1: EXC_BREAKPOINT crash

查看:138
本文介绍了SwiftUI-WKWebView的iOS 13 UIViewRepresentable出现线程1:EXC_BREAKPOINT崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将WKWebView移植到SwiftUI.这是我的代码:

I'm trying to port WKWebView over to SwiftUI. Here's my code:

import SwiftUI
import WebKit

struct ContentView: View {
    var body: some View {
        WebViewWrapper()
    }
}

/**
 WKWebView ported over to SwiftUI with `UIViewRepresentable`.
 */
final class WebViewWrapper: UIViewRepresentable {
    
    /// `UIViewRepresentable` required function #1.
    func makeUIView(context: Context) -> WKWebView  {
        print("make")
        let webView = WKWebView() /// EXC_BREAKPOINT error here
        return webView
    }
      
    /// `UIViewRepresentable` required function #2
    func updateUIView(_ uiView: WKWebView, context: Context) {
    }
}

就是这样.我创建了一个新的SwiftUI项目并将其粘贴.但是,出现此错误:

That's it. I created a new SwiftUI project and pasted it in. However, I get this error:

线程1:EXC_BREAKPOINT(代码= EXC_I386_BPT,子代码= 0x0)

Thread 1: EXC_BREAKPOINT (code=EXC_I386_BPT, subcode=0x0)

...,控制台中未打印任何内容.iOS 13.0和iOS 13.1都发生了这种情况.

... with nothing printed in the console. This happened for both iOS 13.0 and iOS 13.1.

但是,在iOS 14.2上,它工作正常.崩溃似乎也只发生在 WKWebView 上.例如,如果我将其替换为 UITextView ,则它可以正常运行.

But, on iOS 14.2, it works fine. The crash also seems to happen only for WKWebView. For example, if I replace it with UITextView, it runs without problems.

import SwiftUI
import WebKit

struct ContentView: View {
    var body: some View {
        TextViewWrapper()
    }
}

/**
 UITextView ported over to SwiftUI with `UIViewRepresentable`.
 */
final class TextViewWrapper: UIViewRepresentable {
    
    /// `UIViewRepresentable` required function #1.
    func makeUIView(context: Context) -> UITextView  {
        print("make")
        let textView = UITextView() /// no error, works fine
        return textView
    }
      
    /// `UIViewRepresentable` required function #2
    func updateUIView(_ uiView: UITextView, context: Context) {
    }
}

我在M1 Mac上运行Big Sur 11.0.1,但我认为这不是问题.我的Xcode版本是12.2(12B45b).

I'm running Big Sur 11.0.1 on an M1 Mac, but I don't think that should be a problem. My Xcode version is 12.2 (12B45b).

我只是在我的Intel Mac的Catalina 10.15.5上的相同版本的Xcode上运行了它,并且工作正常.

I just ran it on the same version of Xcode on my Intel Mac, Catalina 10.15.5, and it works fine.

推荐答案

问题是由于在M1 Mac上运行并使用14之前的iOS版本所导致的.Apple知道了此问题.

The problem is due to a combination of running on an M1 Mac and using an iOS version prior to 14. The problem is known to Apple.

这篇关于SwiftUI-WKWebView的iOS 13 UIViewRepresentable出现线程1:EXC_BREAKPOINT崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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