首页 > 解决方案 > App UI 将冻结 Firebase MLKit for iOS

问题描述

我有以下代码用于使用 Firebase mlkit for ios 识别文本

func runTextRecognition(with image: UIImage) {

            let visionImage = VisionImage(image: image)
            textRecognizer?.process(visionImage){ result, error in
                guard error == nil, let result = result else {

                    self.addImageToView()

                    return
                }

                for block in result.blocks {
                    self.countDown = self.countDown + 1
                    let blockText = block.text

                    let blockFrame = block.frame

                 //do action
                        }
                        else{

                            print("Tag Total Block Count \(result.blocks.count)")
                            print("Tag Milena \(self.countDown)")

                 /*happen only with some images
                   countDown is less than result.blocks.count
                   UI will be freeze*/

                            if (result.blocks.count == self.countDown){
                                self.countDown = 0
                                print("Tag All Milena \(result.blocks.count)")
                                self.addImageToView()
                            }
                        }
                    }
                }
            }
        }

当块内的文本无法识别时,有时应用程序 UI 将在循环之间冻结。我在代码中也有评论。请任何人都可以帮助我解决这个问题。

标签: iosswiftocrfirebase-mlkit

解决方案


推荐阅读