Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
485 views
in Technique[技术] by (71.8m points)

swift - Strange error nw_protocol_get_quic_image_block_invoke dlopen libquic failed

I'm new to swift and iOS in general, please keep that in mind.

I get this error when opening the CFReadStream. It does not matter if I open the read or write streams, the app always fails.

    var readStream: Unmanaged<CFReadStream>?
    var writeStream: Unmanaged<CFWriteStream>?
    let host: CFString = NSString(string: hostIP)
    let port: UInt32 = UInt32(self.VNCport)
    
    self.password = password
    
    CFStreamCreatePairWithSocketToHost(kCFAllocatorDefault, host, port, &readStream, &writeStream)

    inputStream = readStream!.takeRetainedValue()
    outputStream = writeStream!.takeRetainedValue()
    
    if readStream == nil {
        print("Erro read")
    }
    
    if writeStream == nil {
        print("Erro write")
    }
    
    inputStream!.delegate = self
    outputStream!.delegate = self
    
    inputStream!.schedule(in: RunLoop.main, forMode: RunLoop.Mode.default)
    outputStream!.schedule(in: RunLoop.main, forMode: RunLoop.Mode.default)
    inputStream!.open()
    outputStream!.open()

I made a clean project with just this function and a Button, the result is the same. No quic lib is used in the project.

Can someone help?

question from:https://stackoverflow.com/questions/64029844/strange-error-nw-protocol-get-quic-image-block-invoke-dlopen-libquic-failed

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I faced the same error in a different context, in XCode 12.0.1 too. It might not be related, but I suspect its an issue with accessing the run loop of the main thread. I was just trying out some introductory code I found online, and faced the same issue, so this is a bug, rather than a problem with your code. Here's how you can get a piece of code that has the same issue:

git clone [email protected]:BestKora/CS193P-Fall-2017-Demo-iOS12.git
cd "CS193P-Fall-2017-Demo-iOS12/Cassini L10"
xed . # this opens XCode (CLI tool stands for XCode editor)

Having said that, by rewriting the code, I was able to prevent this issue. Maybe you can find something amongst the code below to fix your specific issue:

Specifically, instead of using the following (DispatchQueue.global)

    private func fetchImage() {
        if let url = imageURL {
            spinner.startAnimating()
            DispatchQueue.global(qos: .userInitiated).async { [weak self] in
                let urlContents = try? Data(contentsOf: url)
                DispatchQueue.main.async {
                    if let imageData = urlContents, url == self?.imageURL {
                        self?.image = UIImage(data: imageData)
                    }
                }
            }
        }
    }

I use URLSession.shared.dataTask, and this error no longer happens:

    private func fetchImage() {
        print("fetching image")
        if let url = imageURL {
            
            let task = URLSession.shared.dataTask(with: url) {(data, response, error) in
                guard let data = data else {
                    return
                }
                // maybe try dispatch to main
                DispatchQueue.main.async {
                    self.imageView.image = UIImage(data: data)
                }
            }
            task.resume()
        }
    }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...